当前位置:网站首页>Regression analysis based on elasticnetcv
Regression analysis based on elasticnetcv
2022-06-12 18:16:00 【Py little brother】
Elastic network regularization (Elastic Net Rerularization) It is a method to reduce the risk of over fitting in regression analysis . The regularization of elastic networks is actually LASSO(The Least Shrinkage and Selection) The phenomenon combination of algorithm and ridge regression algorithm .LASSO Can effectively constrain L1 Norm or Manhattan distance .L1 Norm means that for two points , The sum of the absolute values of the difference between their coordinate values . For ridge regression algorithm L1 The square of the norm is taken as the penalty term .
Define a ElasticNetCV object
clf=ElasticNetCV(max_iter=200,cv=10,l1_ratio=.1)
In the above code ElasticNetCV Class uses a l1_ratio Parameters of , Its value is 0-1, if 0, Then we just use ridge regression algorithm , if 1, Only use LASSO Algorithm . This parameter can be a single value , It can also be a numerical list .
The following is a forecast analysis using the previously preprocessed rainfall data and the California house price data .
For rainfall data , The score is
Scores 0.05276796268304984
It is found that the fitting effect is not good , Under fitting phenomenon occurs . It can also be seen from the picture
For the housing price data, there are
Scores 0.5606109126805701
The complete code is as follows
"XU YONG KANG"
from sklearn.linear_model import ElasticNetCV
import numpy as np
from sklearn import datasets
import matplotlib.pyplot as plt
from sklearn.datasets import fetch_california_housing
def regress(x,y,title):
clf=ElasticNetCV(max_iter=200,cv=10,l1_ratio=.1)
clf.fit(x,y)
print('Scores',clf.score(x,y))
pred=clf.predict(x)
plt.title('Scatter plot of prediction and '+title)
plt.xlabel('Prediction')
plt.ylabel('Target')
plt.scatter(y,pred,color='red')
plt.plot(y,y,label='Fit')
plt.legend()
plt.grid(True)
plt.show()
rain=.1*np.load('rain.npy')
rain[rain<0]=0.05/2
dates=np.load('doy.npy')
x=np.vstack((dates[:-1],rain[:-1]))
y=rain[1:]
regress(x.T,y,'rain data')
housing = fetch_california_housing()
x=housing.data
y=housing.target
regress(x,y,'California house prices')
边栏推荐
- Lightweight and convenient small program to app technology solution to realize interconnection with wechat / traffic app
- Write a select based concurrent server
- Adjust CEPH cluster image source
- 静态内存分配和动态内存分配小结
- VirtualLab basic experiment tutorial -4 Single slit diffraction
- EASYCODE template
- JS moves the 0 in the array to the end
- leetcode 300. Longest increasing subsequence
- First principles of enterprise architecture
- Stream flow precautions
猜你喜欢

Vant3+ts dropdownmenu drop-down menu, multi data can be scrolled

机器学习系列(5):朴素贝叶斯

Gospel of audio and video developers, rapid integration of AI dubbing capability

Vant3 +ts packaged simple step advancer component

Esp-idf adds its own components

GD32F4xx控制DGUS触控按键

轻量、便捷的小程序转App技术方案,实现与微信/流量App互联互通

MYSQL:Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column

Small program +app, a low-cost and active technology combination idea

Extreme Programming -- Practice of root cause analysis
随机推荐
MYSQL:Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column
Still using Microsoft office, 3 fairy software, are you sure you don't want to try?
PHP:Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocat
A method of quickly reusing wechat login authorization in app
SSM integrates FreeMarker and common syntax
Gospel of audio and video developers, rapid integration of AI dubbing capability
VirtualLab基础实验教程-5.泊松亮斑
Schematic diagram of active differential crystal oscillator and differences among lv-pecl, LVDS and HCSL
GD32F4xx控制DGUS触控按键
JS for Fibonacci sequence
Esp32-c3 esp-idf configuring smartconfig and SNTP to obtain network time
Stack in JS (including leetcode examples) < continuous update ~>
HTTP缓存<强缓存与协商缓存>
Eve-ng installation (network device simulator)
leetcode 647. Palindrome substring
面试题总结
Gossip about the source code of redis 89
Virtual Lab Basic Experiment tutoriel - 4. Diffraction à fente unique
ES7 does not use parent-child and nested relationships to implement one to many functions
Codeforces Round #398 (Div. 2) D. Cartons of milk