我需要使用Logistic回归分类器,我有数据集,每列2000的长度,这都是我的代码:
from statistics import mode
import pandas as pd
from sklearn.model_selection import KFold
from sklearn.metrics import plot_confusion_matrix
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import cross_val_predict
from sklearn.linear_model import LogisticRegression
# Importing the datasets
###Social_Network_Ads
datasets = pd.read_csv('C:/Users/n3.csv',header=None)
X = datasets.iloc[:, 0:5].values
Y = datasets.iloc[:, 5].values
# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_Train, X_Test, Y_Train, Y_Test = train_test_split(X, Y, test_size = 0.25, random_state = 0)
# instantiate the model (using the default parameters)
model = LogisticRegression()
# fit the model with data
model.fit(X_Train, Y_Train)
predicted = cross_val_predict(mode, X_Train, Y_Train, cv=5)
train_acc = model.score(X_Train, Y_Train)
print("The Accuracy for Training Set is {}".format(train_acc*100))但在我犯了这个错误:
TypeError:无法在0x000000FD6579B9D0>上克隆对象“<0x000000FD6579B9D0>模式”(键入’>):它似乎不是一个科学工具-学习估计器,因为它没有实现'get_params‘方法。
怎么解决这个问题?
发布于 2022-08-14 14:40:30
更改这一行
predicted = cross_val_predict(mode, X_Train, Y_Train, cv=5) 至
predicted = cross_val_predict(model, X_Train, Y_Train, cv=5) 你有一个简单的错误。您希望将估计器传递给函数,但是却传递了从mode导入的statistics。这就是为什么错误告诉您它不能克隆一个函数类型的对象。您正在传递一个函数,但它需要一个估计器。
https://stackoverflow.com/questions/73352348
复制相似问题