![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
机器学习小算法
野心-优雅
项目产生查询,查询产生积累,积累产生提升
展开
-
why we need to use the zero_grad()
We usually see the "model.optim.zero_grad()" before the model training process. The main functionality of this is to zero the gradient. But do you know why should I do like this.原创 2020-05-18 16:46:47 · 167 阅读 · 0 评论 -
the difference between model.train() and model.eval()
if you have visited many codes in deep-learning writing by pytorch, you will notice that model.train() and model.eval()BUT THE DIFFERENCE BETWEEN THEM DO YOU KNOW?In many cases, the model.train() means that the model would be trained in the following cod原创 2020-05-18 16:10:55 · 176 阅读 · 0 评论 -
how to download cifar10 and split it into training file and testing file in python
how to use cifar10 in pythonthe first step:download the cifar10 using the shell scriptshow to split the cifar10 into training data, testing datahow to change the data more convientthe first step:download the cifar10 using the shell scripts#!/usr/bin/env原创 2020-05-18 11:01:49 · 201 阅读 · 0 评论 -
the knowledge of pytoch
If you want to build a neural network using Pytorch.you have two methods.First,you can use the complete methods to bulid it .Let me show you the code before.import torchimport torch.nn as nnimport...原创 2020-02-16 14:33:27 · 140 阅读 · 0 评论 -
一个检验梯度下降的工具包
import numpy as npdef dg_bug(theta,X_b,y, episilon=0.001): res=np.empty(len(theta)) for i in range(len(theta)): theta_1=theta.copy() theta_1[i]+=episilon theta_2=theta.copy() theta_2[i]-=e...原创 2018-10-22 20:34:26 · 157 阅读 · 0 评论 -
用python实现一个简单的梯度下降程序
import mathimport matplotlib.pyplot as pltimport numpydef dj(theta): return 2*(theta-2.5)#这里返回theta对应的导数,而函数求导是手动进行的def j(theta): return (x-2.5)**2-1def __name__=="__main__":#定义程序的入口 x=np.lin...原创 2018-10-21 19:57:29 · 1398 阅读 · 1 评论 -
python实现knn算法
import numpy as npfrom math import sqrtfrom collections import Counterx=np.random.randint(1,5,size=(4,5))xx=np.reshape(x,(-1,2))y=np.random.randint(0,2,10)#创建一个一维数组,并且指定范围为0,1,大小为10print(y.sha...原创 2018-10-24 18:41:36 · 456 阅读 · 0 评论 -
使用sklearn上的数字测试kNN算法
import numpy as npfrom sklearn import datasetsdigits=datasets.load_digits()x=digits.datay=digits.targetfrom sklearn.model_selection import train_test_splitX_train,X_test,y_train,y_test=train_te...原创 2018-10-24 21:28:20 · 325 阅读 · 0 评论