测试markdown编辑器

测试Markdown编辑器
标题

一级标题

二级标题

三级标题

引用

数学公式块:
\[ \begin{align} h_\theta(\mathbf{x}) &= \theta_0 + \theta_1x_1 + \theta_2x_2+...+\theta_n x_n \\ &=\sum_{i=0}^{n}\theta_ix_i \tag{约定$x_0$=1}\\ &=\left(\begin{array}{} \theta_0 & \theta_1 & \theta_2 & \cdots \end{array}\right) \left(\begin{array}{} x_0 \\ x_1 \\ x_2 \\ \vdots \end{array}\right)\\ &=\mathbf{\theta}^T \mathbf{x}\tag{矩阵形式} \\ \end{align} \]
行内公式:
判断假设好坏的标准:误差 \(|h_\theta(\mathbf{x})-y|\) 越小越好
代码:

#第一步 导入库
import numpy as np #科学计算
import pandas as pd #数据集管理



#第二步 导入数据集
dataset = pd.read_csv(r'datasets\Data.csv')#读取数据集
#X = dataset.iloc[ : , :-1].values
#Y = dataset.iloc[ : , 3].values
X = dataset.iloc[ : , :-1].to_numpy()
Y = dataset.iloc[ : , 3].to_numpy()
#pandas更新至0.24.1以后推荐使用后者
'''
.iloc[] 选取数据的[行,列],允许输入:整数、整数数组、切片
'''

无设置语言

#第三步 处理丢失数据
#数据中有丢失的数据,已经在读取csv过程中被赋值为np.nan,需要对其进行处理,以便后续使用
#通常情况下,使用平均值进行插补

#from sklearn.preprocessing import Imputer
#imputer = Imputer(missing_values = "NaN", strategy = "mean", axis = 0)     #axis = 0,沿列进行插补。
from sklearn.impute import SimpleImputer
imputer = SimpleImputer(missing_values = np.nan, strategy = "mean")
#scikit-learn更新至0.20.2以后推荐使用后者

imputer = imputer.fit(X[ : , 1:3])
X[ : , 1:3] = imputer.transform(X[ : , 1:3])

猜你喜欢

转载自www.cnblogs.com/cbaymax/p/10405377.html