scikit-learn - 在 sklearn 中训练/拟合线性回归,只有一个特征/变量
问题描述
所以我理解套索回归,我不明白为什么当它只是一个二维回归时它需要两个输入值来预测另一个值。
它在文档中说
clf.fit([[0,0], [1, 1], [2, 2]], [0, 1, 2])
我不明白。为什么是[0,0]
or[1,1]
而不仅仅是[0]
or [1]
?
解决方案
[[0,0], [1, 1], [2, 2]]
意味着您有 3 个样本/观察值,每个样本都有 2 个特征/变量(二维)。
实际上,您可以让这 3 个样本只有 1 个特征/变量,并且仍然能够拟合模型。
使用 1 个功能的示例。
from sklearn import datasets
from sklearn import linear_model
# import some data to play with
iris = datasets.load_iris()
X = iris.data[:, :1] # we only take the feature
y = iris.target
clf = linear_model.Lasso(alpha=0.1)
clf.fit(X,y)
print(clf.coef_)
print(clf.intercept_)
推荐阅读
- javascript - 使用html上传要下载的批处理文件
- java - 如何正确地在游戏板上制作鼠标监听器以放置国际象棋
- java - Map myMap = new HashMap 和 HashMap myMap = new HashMap 有什么区别?
- css - CSS 溢出:可见(悬停时)移动按钮以匹配文本
- tensorflow-federated - 如何实现具有不同大小客户端子集的多层架构?
- python - 参数应该是整数或无,而不是'_io.TextIOWrapper'
- ocr - Tesseract 两张相似的图片,一张有效,另一张无效,为什么?
- react-native - 运行 React Native 应用程序时如何获取计算机的 IP 地址?
- javascript - 是否有在 Firefox 中自动重新加载 iframe 的功能?
- google-chrome - chrome如何取消非活动标签的优化?