自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(32)
  • 收藏
  • 关注

原创 面试常见算法题---快速排序python

利用递归进行快速排序class Solution(): def quicksort(self, list, low, high): if low >= high: return list left = low right = high num = list[low] while l...

2018-06-20 18:19:12 996

原创 面试常见算法题---冒泡排序python

两个循环判断相邻数组是否交换class Solution(): def Bubble_sort(self, list): for i in range(len(list)-1, 0, -1): for j in range(i): if list[j] > list[j+1]: ...

2018-06-20 16:16:43 358

原创 面试常见算法题---二分查找(递归) python

class Solution(): def two_part_search(self, list, num, i, j): m = (i+j)//2 if list[m] == num: return m elif list[m] > num: return self.two_part_s...

2018-06-20 15:45:54 358

原创 面试常见算法题---二分查找 python

class Solution(): def seek(self, s, target): i = 0 j = len(s)-1 while i < j: m = (i + j)//2 if s[m] == target: return m ...

2018-06-20 15:31:13 303

原创 面试常见算法题---堆排序python

堆排序class Solution(): def heap_sort(self,heap): root = (len(heap)-2)//2 for i in range(root, -1, -1): left = 2 * i + 1 if heap[left] > heap[i]: ...

2018-06-20 15:13:58 254

原创 python实现 LeetCode43——Multiply Strings

先反序,在统计位数,取模是本位数,除十是进位的数。class Solution(object): def multiply(self, num1, num2): num1=num1[::-1] num2=num2[::-1] carry=0 sum='' arr=[0 for i in range(len(nu...

2018-05-23 23:09:00 470 1

原创 python实现 LeetCode40—— Combination Sum II

和上一个题很像,但是每个数字只能使用一次。class Solution(object): def combinationSum2(self, candidates, target): self.result=[] candidates.sort() start=0 val=[] self.backdate(ca...

2018-05-23 20:56:16 595

原创 python实现 LeetCode39——Combination Sum

利用递归的方式求得和为定值的数,如果目标值小于0,肯定不是解,就break。class Solution(object): def combinationSum(self, candidates, target): candidates = list(set(candidates)) sorted(candidates) self.resul...

2018-05-23 20:48:46 982

原创 kaggle Titanic 简单逻辑回归模型

参考文章点击打开链接首先读取很多很多包和数据#-*-coding:utf-8-*-import pandas as pdimport numpy as npfrom sklearn import preprocessingfrom sklearn.linear_model import LogisticRegressionfrom sklearn.model_selection impo...

2018-04-18 20:06:58 389

原创 kaggle Titanic 数据可视化

参考文章https://zhuanlan.zhihu.com/p/27550334在20世纪初,由英国白星轮船公司耗资7500万英镑打造的当时世界上最大的豪华客轮“泰坦尼克”号,曾被称作为“永不沉没的船”和“梦幻之船”这艘豪轮在她的处女之航中,就因撞上冰山而在大西洋沉没。百年来,关于“泰坦尼克”号沉没的原因,一直是人们争论不休的话题。究竟什么样的人获救几率更大一些呢?这就是本次kaggle的主题,...

2018-04-14 00:15:43 1475

原创 python实现 LeetCode36——Count and Say

count代表这个这个数一共有几个,利用count再加上这个位置的数,最终得到最后的结果class Solution(object): def countAndSay(self, n): string='1' while n>1: string=self.countStr(string) n=n-1 ...

2018-03-28 17:04:10 169

原创 python实现 LeetCode37——Sudoku Solver

数独游戏,用了dfs的深度优先树。25行和26行的else将该位置改为点,是在一次dfs中的,相当于在for循环中不断尝试c值中的赋值。如果所有的c值都不对的时候会进入27行的return false,然后再进入23行的赋值。class Solution(object): def solveSudoku(self, board): def isvaild(i,j): ...

2018-03-28 16:55:19 719

原创 python实现 LeetCode36——Valid Sudoku

利用set函数,查找某个元素是否在set中,更快class Solution(object): def isValidSudoku(self, board): s=set() list=board for i in range(9): for j in range(9): if list...

2018-03-26 20:16:32 366

原创 python实现 LeetCode34——Search for a Range

二分法找到target的位置,再判断前后的位置class Solution(object): def searchRange(self, nums, target): start=0 end=len(nums)-1 while start<=end and start>=0 and end<=len(nums)-1: ...

2018-03-21 20:11:12 219

原创 python实现 LeetCode35——Search Insert Position

自己开始写的代码,不过因为要多判断一次第一个数字,所以感觉不是很整洁,不过也通过了。class Solution(object): def searchInsert(self, nums, target): start=0 end=len(nums) if target<=nums[0]: return 0 ...

2018-03-21 18:57:45 140

原创 python实现 LeetCode33——Search in Rotated Sort

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the a...

2018-03-19 18:49:23 125

原创 斯坦福coursera作业题神经网络训练数字识别Backpropagation

神经网络的后向传播算法的主要思路是:1.生成随机的系数矩阵theta1和theta2,并根据前向传播算法计算得出每个例子为每个数字的概率,在本题中,也就是5000个10*1的矩阵2.再根据已知答案得出真实值和计算值得差值,在通过公式向前推计算出theta1和theta2对应的梯度。3.根据公式theta=theta+α*delta,对于theta进行梯度下降,但此时的步长α是未知的,这

2018-02-09 01:07:24 285

原创 斯坦福coursera作业题神经网络训练数字识别Feedforward Propagation and Prediction

神经网络前馈实现,主要是根据下图def nnCostFunction(theta1,theta2,num_labels, x, y, lamda): m=len(x) one1=np.ones(m) a1=np.column_stack((one1,x)) z2=np.dot(theta1,a1.T) x2=1/(1+np.exp(-z2))

2018-02-05 00:12:02 277

原创 斯坦福coursera作业题神经网络训练数字识别 Visualizing the data python实现

Visualizing the datafrom PIL import Imageimport numpy as npimport matplotlib.pyplot as pltimport scipy.io as sioimport mathimport randomdef displayData(x,y,start,number): #start为起始行

2018-02-04 22:35:06 191

原创 python实现 LeetCode31——Next Permutation

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible

2018-01-05 10:21:49 452

原创 python实现 LeetCode24——Swap Nodes in Pairs

Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y

2017-12-29 01:24:16 479

原创 python实现 LeetCode19——Remove Nth Node From End of List

Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the

2017-12-29 00:19:36 143

原创 斯坦福大学机器学习作业题Problem Set #2 Spam classi cation下篇

最终得出最代表垃圾邮件的五个词为gun,moral,israel,jew,faith将上一篇的main函数替换为这个def main(): trainMatrix, tokenlist, trainCategory = readMatrix('MATRIX.TRAIN') testMatrix, tokenlist, testCategory = readMatrix(

2017-12-27 16:14:14 325

原创 斯坦福大学机器学习作业题Problem Set #2 Spam classi cation

本次作业题的内容是利用朴素贝叶斯分类器识别是否为垃圾邮件,关于文本的提取,分词,和标注都是已成形的数据,只需要写个朴素贝叶斯分类器验证正确率就可以。关于朴素贝叶斯的模型可以参考http://blog.csdn.net/longxinchen_ml/article/details/50597149,讲的很清楚,ng在视频中讲的朴素贝叶斯分类器用的是伯努利模型,即只计算某个词受否存在,而忽略了关于

2017-12-26 00:54:51 433

原创 python2中除法两整数相除为整数

在python2中,2/3 的结果是0,因为除法中是两个整数相除,所以取了整数,改为float(2)/3,就可以了。而python3中不存在这个问题。

2017-12-25 20:24:40 9650

原创 斯坦福大学机器学习作业题Problem Set #1 Regression for denoising quasar spectra 下篇

(i)处理文件# -*- coding: utf-8 -*-import numpy as npimport mathimport matplotlib.pyplot as pltimport csvdef read(): fr=open('quasar_test.csv','r') arrayline=fr.readlines() y=arrayline[1

2017-12-23 01:36:21 368

原创 斯坦福大学机器学习作业题Problem Set #1 Regression for denoising quasar spectra 上篇

# -*- coding: utf-8 -*-import numpy as npimport mathimport matplotlib.pyplot as pltdef read(i): fr=open('quasar_train.csv','r') arrayline=fr.readlines() y=arrayline[1].strip().split(',

2017-12-23 01:33:09 393 1

原创 斯坦福大学机器学习作业题Problem Set #1: Supervised Learning Logistic regression

(a)(b)自己写了个程序跑了下# -*- coding: utf-8 -*-import numpy as npimport mathimport matplotlib.pyplot as pltdef readx(filename): #读取文件 fr=open(filename) arraylines = fr.readlines()

2017-12-20 18:19:06 559

原创 斯坦福大学机器学习作业题Problem Set #0: Linear Algebra and Multivariable Calculus

这章是problem 0,主要是一些数学的基本知识,了解梯度,海瑟矩阵,正定矩阵与半正定矩阵,特征值与特征向量'zheng

2017-12-20 10:49:23 887 1

原创 斯坦福大学机器学习作业题Problem Set #2 Logistic Regression: Training stability--下篇

这题主要是训练调参数的技能。其实做模型也是不断调参换模型的过程。(i)使用不同的学习速率尝试了一下从1到24的迭代次数随着学习速率的不断增加,迭代次数变小,但是当迭代次数大于28的时候,又不收敛了。所以在收敛的情况下,学习速率越大,收敛速度越快。(ii)随着迭代次数的增加,降低学习速率先是使用了e.g中的内容,让学习速率为1/迭代次数,a的收敛速度变很慢,又没法收敛

2017-12-18 21:16:08 687

原创 斯坦福大学机器学习作业题Problem Set #2 Logistic Regression: Training stability--上篇

点击打开链接1. [15 points] Logistic Regression: Training stabilityIn this problem, we will be delving deeper into the workings of logistic regression. The goal of this problem is to help you develop y

2017-12-18 11:57:57 1013

原创 win10(64位)python xgboost详细安装教程---python setup.py install报错原因

         早就听闻xgboost的功能强大,参加数据挖掘比赛的很多大神也都用这个包,我也决定下载下来安装学习一下。上网参考了一些教程,但是这些教程由于比较早,有的存在一些问题,为了大家少走弯路,我把我安装的时候遇到的问题和大家分享一下。         主要是参考了这个教程,http://blog.csdn.net/sb19931201/article/details/52236020 作...

2017-07-20 12:40:13 1189

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除