sklearn Python和Logistic回归

时间:2015-12-02 01:06:16

标签: python scikit-learn logistic-regression

晚安,社区!

我有一个简单的问题,答案可能不那么简单:

如何使用Python SciKit Learn显示Logistic回归模型的自变量系数?

2 个答案:

答案 0 :(得分:1)

如果@IBOutlet weak var mySwitch: UISwitch! @IBOutlet weak var myTextField: UITextField! @IBOutlet weak var User: UITextField! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. // sets the textfield to the intended conversion on load. if mySwitch.on { myTextField.text = "Convert to Celius" } else { myTextField.text = "Convert to Farheniet" } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } // changes the myTextFiled text to the intended conversion when the switch is manually switched on or off @IBAction func switched(sender: AnyObject) { if mySwitch.on { myTextField.text = "Convert to Celsius" } else { myTextField.text = "Convert to Fahrenheit" } } // changes the myTextField text to intended reverse conversion after the buttonClicked func is completed. func stateChanged(switchState: UISwitch) { if switchState.on { myTextField.text = "Convert to Celsius" } else { myTextField.text = "Convert to Fahrenheit" } } // do the intended conversion(old version of XCode 6.4) @IBAction func buttonClicked(sender: AnyObject) { if mySwitch.on { var a = (User.text! as NSString).doubleValue a = (a-32)*(5/9) User.text="\(a)" mySwitch.setOn(false, animated:true) stateChanged(mySwitch) } else { var a = (User.text! as NSString).doubleValue a = a * (9/5) + 32 User.text="\(a)" mySwitch.setOn(true, animated:true) stateChanged(mySwitch) } } 是您的model,那么可以在sklearn.linear_model.LogisticRegression

中访问系数

答案 1 :(得分:1)

如果您希望能够构建完整的线性回归方程式,只需完成上述答案。你不仅需要自变量的系数,还需要截距。您可以通过以下方式访问这些值:

  • 系数:model.coef_
  • 拦截:model.intercept_