本文章仅仅记录本人的学习过程,侵权删。
视频地址:https://www.bilibili.com/video/BV1zb411P7iV
代码和数据:代码和数据
P3. 人工智能的发展和现状
什么是人工智能:
人工智能(Artificial Intelligence) ,英文缩写:AI 。它是研究,开发用于模拟、延伸和扩展人的智能的理论、方法、技术及应用系统的一门新的技术科学。人工智能是计算机科学的一个分支,它试图了解智能的实质,并生产出一种新的能以人类智能相识的方式作出反应的智能机器。
应用场景:
- 机器人
- 语音识别
- 图像识别
- 自然语言处理
- 专家系统
- 知识工程
- 机器学习
人工智能是对人的意识,思维的信息过程的模拟。人工智能不是人的智能,但能像人那样的思考,甚至超过人的智能。
P4.数学分析基础
P5. 线性代数与概率论基础
P6.机器学习基本概念
从学习的方式上分为:
- 监督学习
- 无监督学习
- 半监督学习
- 强化学习
从学习结果上分为:
- 回归
- 分类
P7.线性回归模型
P8.线性回归习题与总结
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import Lasso
from sklearn.linear_model import Ridge
from sklearn.linear_model import ElasticNet
from sklearn.preprocessing import PolynomialFeatures, StandardScaler
from sklearn.pipeline import Pipeline
def generate_lr_train_data(polynomial = False):
if not polynomial:
f = open("./simple_lr.data", "w")
for i in range(200):
f.write("%s %s\n" % (i, i * 3 + np.random.normal(0, 50)))
else:
f = open("./polynomial_lr.data", "w")
for i in range(200):
f.write("%s %s\n" % (i, 1 / 20 * i * i + i + np.random.normal(0, 80)))
f.close()
def read_lr_train_data(polynomial = False):
if not polynomial:
return pd.read_csv("./simple_lr.data", header = None)
else:
return pd.read_csv("./polynomial_lr.data", header = None)
def simple_linear_regression():
# if polynomial used
polynomial = True
# generate simple lr train data
generate_lr_train_data(polynomial)
# read simple lr train data 读取数据
lr_data = read_lr_train_data(polynomial)
clean_data = np.empty((len(lr_data), 2))
for i, d in enumerate(lr_data.values):#数据清洗,去除重复行
clean_data[i] = list(map(float, list(d[0].split(' '))))
x, y = np.split(clean_data, (1, ), axis = 1) # split array to shape [:1],[1:] 切割
y = y.ravel()
print("样本个数:%d,特征个数:%d" % x.shape)
#划分训练集和测试集
x_train, x_test, y_train, y_test = train_test_split(x, y, train_size = 0.7, random_state = 0)
model = Pipeline([("ss", StandardScaler()),
("polynomial", PolynomialFeatures(degree = 60, include_bias = True)),#升幂
#("linear", Lasso(alpha=10))
("linear", LinearRegression()) # 这里可以在选择普通线性回归、Lasso/Ridge
])
print("开始建模")
model.fit(x_train, y_train)
y_pred = model.predict(x_train)
print("建模完毕")
# 绘制前调整数据
order = x_train.argsort(axis=0).ravel()
x_train = x_train[order]
y_train = y_train[order]
y_pred = y_pred[order]
# 绘制拟合曲线
mpl.rcParams["font.sans-serif"] = ["simHei"]
mpl.rcParams["axes.unicode_minus"] = False
plt.figure(facecolor = "w", dpi = 200)
plt.scatter(x_train, y_train, s = 5, c = "b", label = "实际值")
plt.plot(x_train, y_pred, "g-", lw = 1, label = "预测值")
plt.legend(loc="best")
plt.title("简单线性回归预测", fontsize=18)
plt.xlabel("x", fontsize=15)
plt.ylabel("y", fontsize=15)
plt.grid()
plt.show()
if __name__ == "__main__":
simple_linear_regression()
用(“linear”, Lasso(alpha=10))产生的:
用(“linear”, LinearRegression())产生的:
P9.Logistic回归模型与练习
import numpy