![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
机器学习
不 知
by design.
展开
-
机器学习_梯度下降法一维函数
一维函数使用梯度下降法的例子import numpy as npimport matplotlib as mplimport matplotlib.pyplot as pltdef f1(x): return 0.5 * (x - 0.25) ** 2def h1(x): return 0.5 * 2 *(x - 0.25)if __name__ == '__main__': mpl.rcParams['font.family'] = 'SimHei' mp原创 2020-12-28 18:50:14 · 684 阅读 · 0 评论 -
机器学习_线性回归最小二乘法求解
import sklearn.datasets as dataimport numpy as npimport matplotlib.pyplot as pltimport pandas as pdimport matplotlib as mplclass LinearRegression: def __init__(self): pass def fit(self, X, y): X = np.asmatrix(X.copy())原创 2020-12-28 15:45:55 · 167 阅读 · 0 评论 -
机器学习_线性回归梯度下降法求解
import numpy as npimport pandas as pdimport sklearn.datasets as datasetimport matplotlib.pyplot as pltimport matplotlib as mplclass LinearRegression: def __init__(self, alpha, times): """ alpha:float 学习率,用来控制步长(权重调整的幅原创 2020-12-28 15:45:01 · 96 阅读 · 0 评论 -
机器学习_感知器算法学习(Python实现)
感知器是一种分类算法,代码实现如下:import numpy as npimport pandas as pdimport matplotlib as mplimport matplotlib.pyplot as pltimport sklearn.datasets as datasetclass Perception: def __init__(self, alpha, times): """ 初始化方法 :param alpha:学原创 2020-11-19 11:31:38 · 347 阅读 · 0 评论 -
机器学习_KMeans聚类算法的学习(Python实现)
Kmeans算法是最常用的聚类算法。主要思想是:在给定K值和K个初始类簇中心点的情况下,把每个点(亦即数据记录)分到离其最近的类簇中心点所代表的类簇中,所有点分配完毕之后,根据一个类簇内的所有点重新计算该类簇的中心点(取平均值),然后再迭代的进行分配点和更新类簇中心点的步骤,直至类簇中心点的变化很小,或者达到指定的迭代次数。其训练数据的流程是:根据上面的流程图来实现具体代码:import numpy as npimport matplotlib as mplimport matplotl.原创 2020-11-19 10:54:55 · 1683 阅读 · 0 评论 -
Python中numpy添加元素
首先这里p_arr为一个numpy的array,p_为一个元素p_arr = np.concatenate((p_arr,[p_])) # 先将p_变成list形式进行拼接,注意输入为一个tuplep_arr = np.append(p_arr,p_) #直接向p_arr里添加p_#注意一定不要忘记用赋值覆盖原p_arr不然不会变...原创 2020-11-13 11:43:15 · 6161 阅读 · 0 评论 -
python实现KNN分类算法
import sklearnimport numpy as npfrom sklearn.neighbors import KNeighborsClassifierimport sklearn.datasets as dataimport matplotlib as mplimport matplotlib.pyplot as pltfrom matplotlib.colors import ListedColormapimport pandas as pdfrom tensorboard.原创 2020-11-11 20:45:58 · 166 阅读 · 1 评论 -
Python语法np.c_分析、np.meshgrid、plt.pcolormesh和分类器
1、np.c_和np.r_直接上代码:多维的数据: d = np.array([[1, 2, 3], [4, 5, 6]]) c = np.array([[4,5,6],[7,8,9]]) print(np.c_[d,c])[[1 2 3 4 5 6] [4 5 6 7 8 9]] 一维的数据: d = np.array([1, 2, 3]) c = np.array([4,5,6]) print(np.c_[d,c])[[1 4] [2 5] [原创 2020-11-09 21:33:52 · 1590 阅读 · 0 评论 -
Python机器学习记录_KNN预测男女
import sklearnimport numpy as npfrom sklearn.neighbors import KNeighborsClassifierimport sklearn.datasets as dataif __name__ == '__main__': x_train = [[192,90,46],[180,80,44],[160,45,36],[170,65,41],[154,41,34],[165,60,40]] y_train = ["boy","b原创 2020-11-07 14:38:22 · 581 阅读 · 0 评论