我使用sklearn.linear_模型.ElasticNetCV和我希望得到一个类似于Matlab提供的带有plottype=CV
或R的{
import sklearn.linear_model as lm
import matplotlib.pyplot as plt
import numpy as np
import scipy as sp
import scipy.stats as stats
# toy example
# generate 200 samples of five-dimensional artificial data X from a
# exponential distributions with various means:
X = np.zeros( (200,5 ) )
for col in range(5):
X[ :, col ] = stats.expon.rvs( scale=1.0/(col+1) )
# generate response data Y = X*r + eps where r has just two nonzero
# components, and the noise eps is normal with standard deviation 0.1:
r = np.array( [ 0, 2, 0, -3, 0 ] )
Y = np.dot(X,r) + sp.randn( 200 )*0.1
enet = lm.ElasticNetCV()
alphas,coefs, _ = enet.path( X, Y )
# plot regulization paths
plt.plot( -np.log10(alphas), coefs.T, linestyle='-' )
plt.show()
我还想在一个单独的图中绘制每个alpha的交叉验证错误。但看起来弹性网络路径()不返回mse向量。sklearn中是否有类似的功能Matlab.lassoPlot
与plottype='CV'
见:http://de.mathworks.com/help/stats/lasso-and-elastic-net.html或R cv.glmnet(x,y)
https://web.stanford.edu/~hastie/glmnet/glmnet_alpha.html。或者,我将使用sklearn.cross_validation
来实现它。你有什么建议吗?在
目前没有回答
相关问题 更多 >
编程相关推荐