python - python使用sklearn进行线性回归
问题描述
我尝试用 python 做线性回归
例如
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
x = [[6, 2], [8, 1], [10, 0], [14, 2], [18, 0]]
y = [[7], [9], [13], [17.5], [18]]
model = LinearRegression()
model.fit(x, y)
x_test = [[8, 2]]
现在 example_data 像:
inches city Pizza_Price
5 A 10
6 B 12
英寸是一个明确的数字,但面积不是。
如何将城市转换为数字进行计算?</p>
如何将城市等参数分类为数字进行计算?</p>
解决方案
代码:
from sklearn import preprocessing
le = preprocessing.LabelEncoder()
cities = ['A','B','C','B'] # for example
le.fit(cities)
cities = le.transform(cities)
print(cities)
输出:
[0, 1, 2, 1]
推荐阅读
- java - 最佳实践访问不同类中的几个参数
- java - 使用登录屏幕密码选择服务器
- elasticsearch - Elasticsearch 一个数组至少包含一个元素
- elasticsearch - Jasper Webservice 适配器是否通过过滤某些字符来更改 REST 请求正文?
- bash - 删除空行后从文本文件中选择随机行
- spring - 使用 WebFlux 和 Keycloak 在 Spring Boot 中上传多部分表单数据时出现问题
- python - Python TKinter 事件 - 关闭窗口
- android - 链接共享 C 库时出现 Android NDK 错误
- windows - DNS更改.bat脚本适用于Win7但不适用于Win10
- javascript - 添加带有样式组件的活动类不起作用