我想创建烧瓶应用程序,但我得到了以下错误
(<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
,那么问题是:
X
和Y
是字符串,也就是说,它们的值分别为"X.csv"one_answers"Y.csv">
根据文件,允许的输出为:
允许的输入是列表、numpy数组、scipy稀疏矩阵或panda数据帧。
例如,您必须使用pandas
打开这些CSV文件。