【发布时间】:2019-02-22 23:06:36
【问题描述】:
我有一个在 Logistic RegressionCV 中实现 KFold 的程序。我已经设置了一个种子并在 KFOLD 和 LogisticRegressionCV 中使用它。即使设置了种子,每次重新运行内核时,我都会对所有指标进行不同的测量。代码如下:
rs = random.seed(42)
X_train, X_test, y_train, y_test = train_test_split(X_smt, y_smt, test_size=0.1,
random_state=42)
kf = KFold(n_splits=15, shuffle=flase, random_state=42)
logistic = LogisticRegressionCV(Cs=2, fit_intercept=True, cv=kf, verbose =1, random_state=42)
logistic.fit(X_train, y_train)
print("Train Coefficient:" , logistic.coef_) #weights of each feature
print("Train Intercept:" , logistic.intercept_) #value of intercept
print("\n \n \n ")
logistic.predict(X_test)
test_precision = metrics.precision_score(y_test, logistic.predict(X_test))
test_avg_precision = metrics.average_precision_score(y_test, logistic.predict(X_test))
这可能是什么原因,是否有简单的解决方案。
【问题讨论】:
标签: python logistic-regression cross-validation seed