我想创建flask应用程序,但出现以下错误
(<class 'ValueError'>, ValueError("could not convert string to float: 'X'"), <traceback object at 0x0000022B617C0280>)
这是我的app.py,我的app.py目录中有X.csv和Y.csv文件
imports..
app = Flask(__name__)
X = 'X.csv'
Y = 'Y.csv'
# Splitting the dataset into the Training set and Test set
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.2, random_state=0)
# Scaling data
sc = StandardScaler()
x_train = sc.fit_transform(x_train)
x_test = sc.transform(x_test)
# Oversample data
smk = SMOTETomek()
# Training data
x_train, y_train = smk.fit_sample(x_train, y_train)
# Testing data
x_test, y_test = smk.fit_sample(x_test, y_test)
# Fitting RandomForestClassifier to the Training set
rfr = RandomForestClassifier()
rfr.fit(x_train, x_train)
# Predicting the Test set results
y_pred = rfr.predict(x_test)
# Saving model to disk
pickle.dump(rfr, open('model.pkl', 'wb'))
# Loading model to compare the results
model = pickle.load(open('model.pkl', 'rb'))
首先,请不要像那样“缩短”你的进口。进口实际上很重要
假设
train_test_split
是指sklearn.model_selection.train_test_split
文档化here,那么问题在于:X
和Y
是字符串-也就是说,它们的值分别是“X.csv”和“Y.csv”李>根据文件,允许的输出为:
例如,必须使用
pandas
打开这些CSV文件相关问题 更多 >
编程相关推荐