Elastic Net
来源:互联网 发布:水利工程力学分析软件 编辑:程序博客网 时间:2024/05/20 02:56
# coding:utf-8import sklearn.datasetsimport sklearn.linear_modelimport numpy.randomimport numpy.linalgimport matplotlib.pyplotif __name__ == "__main__": # Load boston dataset boston = sklearn.datasets.load_boston() # Split the dataset with sampleRatio sampleRatio = 0.5 n_samples = len(boston.target) sampleBoundary = int(n_samples * sampleRatio) # Shuffle the whole data shuffleIdx = range(n_samples) numpy.random.shuffle(shuffleIdx) # Make the training data train_features = boston.data[shuffleIdx[:sampleBoundary]] train_targets = boston.target[shuffleIdx[:sampleBoundary]] # Make the testing data test_features = boston.data[shuffleIdx[sampleBoundary:]] test_targets = boston.target[shuffleIdx[sampleBoundary:]] # Train elasticNet = sklearn.linear_model.ElasticNetCV(alphas = [0.01, 0.05, 0.1, 0.5, 1.0, 10.0], l1_ratio = [0.1, 0.3, 0.5, 0.7, 0.9]) elasticNet.fit(train_features, train_targets) print("Alpha = ", elasticNet.alpha_) print("L1 Ratio = ", elasticNet.l1_ratio_) # Predict predict_targets = elasticNet.predict(test_features) # Evaluation n_test_samples = len(test_targets) X = range(n_test_samples) error = numpy.linalg.norm(predict_targets - test_targets, ord = 1) / n_test_samples print("Elastic Net (Boston) Error: %.2f" %(error)) #Draw matplotlib.pyplot.plot(X, predict_targets, 'r--', label = 'Predict Price') matplotlib.pyplot.plot(X, test_targets, 'g:', label='True Price') legend = matplotlib.pyplot.legend() matplotlib.pyplot.title("Elastic Net (Boston)") matplotlib.pyplot.ylabel("Price (1000 U.S.D)") matplotlib.pyplot.savefig("Elastic Net (Boston).png", format='png') matplotlib.pyplot.show()
0 0
- Elastic Net
- Ridge & LASSO & Elastic Net
- scikit-learn学习:elastic net
- elastic
- elastic
- LASSO, sparse group LASSO, elastic net
- LASSO, sparse group LASSO, elastic net
- Lasso和Elastic net的区别
- L0、L1、L2、Elastic Net正则项
- 4.弹性网络( Elastic Net)
- 岭回归、LASSO与elastic net
- L0、L1、L2、Elastic Net正则项
- 4.弹性网络( Elastic Net)
- 弹性网络( Elastic Net) 多任务 Lasso回归 MultiTaskLasso
- scikit-learn中的Lasson回归和Elastic Net回归
- elastic编译
- elastic search
- elastic buffer
- 【屏幕适配】Android 全方位解析屏幕适配问
- MFC CScrollView中的设备坐标和逻辑坐标转换
- 搭建XMPP协议,实现自主推送消息到手机
- DUKPT算法简析-1
- 毕业设计之 “安卓新浪微博客户端” 开发笔记(1)
- Elastic Net
- Docker实践6:Cannot connect to the Docker daemon.
- 从零开始学习OpenCL开发(二)一个最简单的示例与简单性能分析
- JavaScript学习总结(五)——Javascript中==和===的区别
- Ocloud的使用问题记录
- 搜索策略
- ECLIPSE快捷键大全 掌握了这个看着你就牛
- webservice创建
- Android AIDL使用详解