[英]Errno 36 :File name too long: "testLogisticRegression"
I have a function that does classification.我有一个做分类的功能。 I am encountering a problem when exporting data.我在导出数据时遇到问题。 Here is the stack trace:这是堆栈跟踪:
[Errno 36] File name too long: "testLogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,\n intercept_scaling=1, l1_ratio=None, max_iter=100,\n multi_class='warn', n_jobs=None, penalty='l2',\n random_state=None, solver='warn', tol=0.0001, verbose=0,\n warm_start=False).xlsx"
My code :我的代码:
def classifieur(X, y):
X = matrix(X)
model_l = LinearSVC()
model_m = MultinomialNB()
model_lr = LogisticRegression()
model_r = RandomForestClassifier()
model_k = KNeighborsClassifier()
models = [model_l, model_m, model_lr, model_r, model_k]
cv_splitter = KFold(n_splits=10, shuffle=False, random_state=None)
for model in models:
y_pred = cross_val_predict(model, X, y, cv=cv_splitter)
print("Model: {}".format(model))
print("Accuracy: {}".format(accuracy_score(y, y_pred)))
# export
res = pd.DataFrame()
res['Expected Output'] = y
res['Predicted Output'] = y_pred
print(output.head())
res.to_excel("test{}.xlsx".format(model))
classifieur(X, y)
The function works.该功能有效。 It is just the name of the file that poses a problem.只是文件名有问题。 I am working in a linux environment.我在 linux 环境中工作。
Create a dict with model name and model value and use the model name as file name:创建一个带有模型名称和模型值的字典,并使用模型名称作为文件名:
def classifieur(X, y):
X = matrix(X)
model_l = LinearSVC()
model_m = MultinomialNB()
model_lr = LogisticRegression()
model_r = RandomForestClassifier()
model_k = KNeighborsClassifier()
models = {'model_l': model_l, 'model_m': model_m, 'model_lr': model_lr, 'model_r': model_r, 'model_k': model_k}
cv_splitter = KFold(n_splits=10, shuffle=False, random_state=None)
for model_name, model in models.items():
y_pred = cross_val_predict(model, X, y, cv=cv_splitter)
print("Model: {}".format(model))
print("Accuracy: {}".format(accuracy_score(y, y_pred)))
# export
res = pd.DataFrame()
res['Expected Output'] = y
res['Predicted Output'] = y_pred
print(output.head())
res.to_excel("test{}.xlsx".format(model_name))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.