Logistic回归-Python?

问题描述 投票:0回答:4

您能否简要描述以下代码行的含义?这是Python中逻辑回归的代码。

什么意思是大小= 0.25且random_state = 0?什么是train_test_split?在这行代码中做了什么?

X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.25,random_state=0)

这些代码行做了什么?

logistic_regression= LogisticRegression()
logistic_regression.fit(X_train,y_train)
y_pred=logistic_regression.predict(X_test) 
python pandas scikit-learn regression
4个回答
1
投票

在这里查看the description of the function

  • [random_state为随机数生成器设置种子,以使您在每次运行中获得相同的结果,在教育设置中为每个人提供相同的结果特别有用。
  • [test_size是指测试拆分中使用的比例,此处75%的数据用于训练,25%的数据用于测试模型。

其他行仅对训练数据集运行逻辑回归。然后,您可以使用测试数据集来检查拟合回归的优劣。


1
投票

什么表示大小= 0.25且random_state = 0?

[test_size=0.25->训练和测试数据的25%分配。

random_state = 0->为可再现的结果,它可以是任意数字。

此行代码做了什么?

Xy拆分为X_train, X_test, y_train, y_test

这些代码行做了什么?

通过fit(X_train, y_train)训练逻辑回归模型,然后对测试集X_test进行预测。

稍后您可能会比较y_predy_test以查看模型的准确性。


0
投票

X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.25,random_state=0)

以上行将您的数据随机分为训练和测试数据

  • X是您的数据集减去输出变量
  • y是您的输出变量
  • test_size = 0.25表示您将数据划分为75%-25%,其中25%是测试数据集
  • random_state用于在运行代码时再次生成相同的样本

参考train-test-split documentation


0
投票

此行:

X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.25,random_state=0)

将您的来源分为训练和测试集,0.25表示25%的来源将用于测试,其余部分将用于训练。

对于,random_state = 0,这是brief discussion。链接上方的一部分:

如果您使用random_state = some_number,则可以保证运行1的输出将等于运行2的输出,

logistic_regression= LogisticRegression() #Creates logistic regressor

为您的来源计算一些值。 Recommended read

logistic_regression.fit(X_train,y_train) 

链接上方的一部分:

在这里,拟合方法在应用于训练数据集时,将学习模型参数(例如,均值和标准差)

基于对训练集的学习,对测试集进行预测。

y_pred=logistic_regression.predict(X_test) 
© www.soinside.com 2019 - 2024. All rights reserved.