Machine Learning Foundations q15
2014-10-14 13:52
246 查看
# -*- coding: utf-8 -*- import fileinput import numpy as np def install(fileName): xSet=[] ySet=[] for line in fileinput.input(fileName): num_str = line.split() xSet.append(map(float, num_str[0:-1])) ySet.append(int(num_str[-1])) return (np.matrix(xSet),np.matrix(ySet).T) xSet,ySet=install('hw1_15_train.dat') #从训练集中读取 xSet = np.concatenate((np.ones((xSet.shape[0],1)), xSet), 1) w = np.matrix(np.zeros(5)) #初始化w,[[ 0. 0. 0. 0. 0.]] count = 0 while True: correct_num = 0 for i in xrange(np.shape(xSet)[0]): #从martix里提取行数 xn = xSet[i] yn = ySet[i] dot = np.dot(xn,w.T) if dot*yn <=0: w += yn*xn count = count + 1 else: correct_num = correct_num + 1 if correct_num == 400: break else: print correct_num print count, w
相关文章推荐
- 機器學習基石(Machine Learning Foundations) 机器学习基石 作业三 Q13-15 C++实现
- Machine Learning Foundations 作业二 Question 10 解答
- Foundations of Machine Learning: The PAC Learning Framework(1)
- Machine Learning Foundations - week1 key point
- Foundations of Machine Learning: The Margin Explanation for Boosting's Effectiveness
- 機器學習基石(Machine Learning Foundations) 机器学习基石 作业四 Q13-20 MATLAB实现
- Machine Learning Foundations: A Case Study Approach-Regression-Assignment: Predicting House Prices
- Foundations of Machine Learning: Rademacher complexity and VC-Dimension(1)
- Machine Learning Foundations - week2 key point
- 機器學習基石(Machine Learning Foundations) 机器学习基石 课后习题链接汇总
- Machine Learning Foundations - week3 key point
- 机器学习中的神经网络Neural Networks for Machine Learning:Lecture 15 Quiz
- 機器學習基石(Machine Learning Foundations) 机器学习基石 作业四 课后习题解答
- Machine Learning Foundations 第9节-第12节
- (机器学习基石)Machine Learning Foundations:Lecture 1
- 機器學習基石 机器学习基石 (Machine Learning Foundations) 作业二 Q19-20 C++实现
- 機器學習基石(Machine Learning Foundations) 机器学习基石 作业四 Q13-20 MATLAB实现
- CalTech machine learning, video 15 note(Kernel Method)
- 機器學習基石 机器学习基石(Machine Learning Foundations) 作业1 习题解答
- Machine Learning Foundations(机器学习基石)笔记 第一节