LogisticRegression逻辑回归
来源:互联网 发布:黑苹果mac安装办公软件 编辑:程序博客网 时间:2024/06/05 08:36
# coding:utf-8import sklearn.datasetsimport sklearn.linear_modelimport numpy.randomimport matplotlib.pyplotif __name__ == "__main__": # Load iris dataset iris = sklearn.datasets.load_iris() # Split the dataset with sampleRatio sampleRatio = 0.5 n_samples = len(iris.target) sampleBoundary = int(n_samples * sampleRatio) # Shuffle the whole data shuffleIdx = range(n_samples) numpy.random.shuffle(shuffleIdx) # Make the training data train_features = iris.data[shuffleIdx[:sampleBoundary]] train_targets = iris.target[shuffleIdx[:sampleBoundary]] # Make the testing data test_features = iris.data[shuffleIdx[sampleBoundary:]] test_targets = iris.target[shuffleIdx[sampleBoundary:]] # Train logisticRegression = sklearn.linear_model.LogisticRegression() logisticRegression.fit(train_features, train_targets) # Predict predict_targets = logisticRegression.predict(test_features) # Evaluation n_test_samples = len(test_targets) X = range(n_test_samples) correctNum = 0 for i in X: if(predict_targets[i] == test_targets[i]): correctNum += 1 accuracy = correctNum * 1.0 / n_test_samples print("Logistic Regression (Iris) Accuracy: %.2f" %(accuracy)) # Draw matplotlib.pyplot.subplot(2, 1, 1) matplotlib.pyplot.title("Logistic Regression (Iris)") matplotlib.pyplot.plot(X, predict_targets, 'ro-', label = 'Predict Labels') matplotlib.pyplot.ylabel("Predict Class") legend = matplotlib.pyplot.legend() matplotlib.pyplot.subplot(2, 1, 2) matplotlib.pyplot.plot(X, test_targets, 'g+-', label='True Labels') legend = matplotlib.pyplot.legend() matplotlib.pyplot.ylabel("True Class") matplotlib.pyplot.savefig("Logistic Regression (Iris).png", format='png') matplotlib.pyplot.show()
0 0
- LogisticRegression逻辑回归
- Sklearn-LogisticRegression逻辑回归
- 逻辑回归LogisticRegression
- SparkMLlib---LinearRegression(线性回归)、LogisticRegression(逻辑回归)
- (sklearn)逻辑回归linear_model.LogisticRegression用法
- 【甘道夫】基于scikit-learn实现逻辑回归LogisticRegression
- 机器学习实战(四)——logisticRegression逻辑回归
- Spark MLlib 源代码解析之逻辑回归LogisticRegression
- c++实现LogisticRegression/用c++实现逻辑回归
- 逻辑斯蒂回归(LogisticRegression)sklearn的一个例子中文解释
- 使用Spark MLlib的逻辑回归(LogisticRegression)进行用户分类预测识别
- 【python数据挖掘课程】十六.逻辑回归LogisticRegression分析鸢尾花数据
- LogisticRegression
- LogisticRegression
- LogisticRegression
- 逻辑回归
- 逻辑回归
- 逻辑回归
- ORACLE PL/SQL 概念
- 三表左外连接的实例
- hdu 4691 Front compression (后缀数组+rmq)
- JavaScript prototype
- 用python生成验证码
- LogisticRegression逻辑回归
- 编程实现单链表反转。
- SVM支持向量机-拉格朗日,对偶算法的初解
- 二零一五年 年度
- poj 1959 Darts
- centos安装NVI驱动
- C#中含有多个Main函数的处理
- CString.Format报Buffer too small问题
- SecureCRT 绝佳配色方案, 保护你的眼睛