没有定义“classification_model”的名称

时间:2021-08-07 10:13:51

Im trying to model in Python 3.5 and am following an example that can be found at here.

我正在尝试用Python 3.5建模,并且正在遵循一个可以在这里找到的示例。

I have imported all the required libraries from sklearn.

我已经从sklearn导入了所有必需的库。

However I'm getting the following error.

但是我得到了下面的错误。

Code:

代码:

  from sklearn.linear_model import LogisticRegression
  from sklearn.cross_validation import KFold   #For K-fold cross validation
  from sklearn.ensemble import RandomForestClassifier
  from sklearn.tree import DecisionTreeClassifier, export_graphviz
  from sklearn import metrics

 outcome_var = 'Loan_Status'
 model = LogisticRegression()
 predictor_var = ['Credit_History']
 classification_model(model, loan,predictor_var,outcome_var)

When I run the above code I get the following error: NameError: name 'classification_model' is not defined

当我运行上面的代码时,我得到以下错误:NameError: name 'classification_model'没有定义

I'm not sure how to resolve this as I tried importing sklearn and all the sub libraries.

我不知道如何解决这个问题,因为我尝试了导入sklearn和所有的子库。

P.S. I'm new to Python, hence I'm trying to figure out basic steps

另外,我是Python的新手,因此我正在尝试找出基本的步骤

2 个解决方案

#1


0  

Depending on the exact details this may not be what you want but I have never had a problem with

根据具体细节,这可能不是你想要的,但我从来没有遇到过问题

 import sklearn.linear_model as sk

 logreg = sk.LogisticRegressionCV()
 logreg.fit(predictor_var,outcome_var)

This means you have to explicitly separate your training and test set, but having fit to a training set (the process in the final line of my code), you can then use the methods detailed in the documentation [1].

这意味着您必须显式地分离您的训练和测试集,但是如果适合一个训练集(我代码的最后一行中的过程),那么您可以使用文档[1]中详细介绍的方法。

For example figuring out what scores (how many did I get correct) you get on unseen data with the .score method

例如,计算出哪些分数(我得到了多少正确的分数)可以用.score方法获得看不见的数据。

[1] http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegressionCV.html

[1]http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegressionCV.html

#2


0  

It appears this code came from this tutorial.

这段代码似乎来自本教程。

The issue is exactly as the error describes. classification_model is currently undefined. You need to create this function yourself before you can call it. Check out this part of that tutorial so you can see how it's defined. Good luck!

问题与错误描述的完全一样。classification_model目前定义。您需要自己创建这个函数,然后才能调用它。请查看本教程的这一部分,以便了解它是如何定义的。好运!

#1


0  

Depending on the exact details this may not be what you want but I have never had a problem with

根据具体细节,这可能不是你想要的,但我从来没有遇到过问题

 import sklearn.linear_model as sk

 logreg = sk.LogisticRegressionCV()
 logreg.fit(predictor_var,outcome_var)

This means you have to explicitly separate your training and test set, but having fit to a training set (the process in the final line of my code), you can then use the methods detailed in the documentation [1].

这意味着您必须显式地分离您的训练和测试集,但是如果适合一个训练集(我代码的最后一行中的过程),那么您可以使用文档[1]中详细介绍的方法。

For example figuring out what scores (how many did I get correct) you get on unseen data with the .score method

例如,计算出哪些分数(我得到了多少正确的分数)可以用.score方法获得看不见的数据。

[1] http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegressionCV.html

[1]http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegressionCV.html

#2


0  

It appears this code came from this tutorial.

这段代码似乎来自本教程。

The issue is exactly as the error describes. classification_model is currently undefined. You need to create this function yourself before you can call it. Check out this part of that tutorial so you can see how it's defined. Good luck!

问题与错误描述的完全一样。classification_model目前定义。您需要自己创建这个函数,然后才能调用它。请查看本教程的这一部分,以便了解它是如何定义的。好运!