and技术梦
2019-11-07 07:01
采纳率: 66.7%
浏览 398

简单的机器学习更改,指定数据集预测

就是我行对train文件训练后,直接训练test.xls。请问这个应该怎么办呢,越简单越好。

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
#from competition.ml import score

%matplotlib inline
%config InlineBackend.figure_format = 'retina'
%config IPCompleter.greedy = True
%config IPCompleter.use_jedi = True
pd.options.display.max_colwidth = 100
plt.rcParams['figure.figsize'] = (12, 8)

train_path = r'C:\Users\MyPC\Desktop\train.xls'
test_path = r'C:\Users\MyPC\Desktop\test.xls'
train = pd.read_excel(train_path)
test = pd.read_excel(test_path)
train.shape, test.shape

train.info()
test.info()
train.head()
test.head()
train.describe()
test.describe()



from sklearn.ensemble import ExtraTreesClassifier
model=ExtraTreesClassifier()

trainX=train[['X1','X2','X3','X4','X5','X6','X7','X8','X9','X10','X11','X12','X13','X14','X15','X16','X17','X18','X19','X20','X21','X22','X23']]
trainY=train['Y']

testX=train[['X1','X2','X3','X4','X5','X6','X7','X8','X9','X10','X11','X12','X13','X14','X15','X16','X17','X18','X19','X20','X21','X22','X23']]
testY=train['Y']

model.fit(trainX,trainY)
y_pred =model.predict(testX)#######预测

np.savetxt(r'C:\Users\MyPC\Desktop\predict.csv', y_pred)
#score(y_pred)



就是我行对train文件训练后,直接训练test.xls。请问这个应该怎么办呢,越简单越好。
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • 二心TOT 2019-11-08 09:28
    已采纳

    首先,不建议这么做,如果把train和test都用来训练,没测试集来看效果。
    如果真要这么做,可以在训练前先把两个文件合并再投入训练

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题