python机器学习1--鸢尾花分类--环境准备与数据显示

学习《Python机器学习》(Sebastian著)过程中的笔记记录。

PC:ThinkPAd T480

VMware workstation pro14 :VMware-workstation-full-14.1.1-7528167

Ubuntu :16.04

 

1:早期感知器学习算法

1.1:感知器概念

        弗兰克·罗森布拉特(Frank Rossenblatt)基于MCP神经元模型提出了第一个感知器 学习法则。主要实现了以下几步:

1)将感知器的权重初始化为0或者一个极小的随机数

2)迭代所有训练样本x(i),执行如下操作

       (1)计算输出值y

         (2)更新权重

一个简要的概述图如下:

          感知器接收样本x的输入,并将其与权值w进行加权以计算净输入(net input)。进而净输入被传递到激励函数(在此为单位阶跃函数),然后生成值为+1或者-1的二值输出,并以其作为样本的预测类标。在学习阶段,此输出用来计算预测的误差并更新权重。
 

1.2:使用python实现感知器学习算法

1.2.1:安装pip

获取pip的安装脚本

                 python3 get-pip.py 

利用python3安装pip

                 sudo python3 get-pip.py

在利用pip安装pandas包的时候,如果出现python版本太低错误

sudo pip install pandas -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
WARNING: The directory '/home/xiankun/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
WARNING: The directory '/home/xiankun/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Looking in indexes: http://pypi.douban.com/simple
Collecting pandas
  Downloading http://pypi.doubanio.com/packages/a9/55/e3f34ad611f703454b951bab6bde9a432f1af92994cebc4d8e0ec0af38c4/pandas-0.25.3-cp35-cp35m-manylinux1_x86_64.whl (10.3MB)
     |████████████████████████████████| 10.3MB 1.2MB/s 
ERROR: Package 'pandas' requires a different Python: 3.5.2 not in '>=3.5.3'
 

解决方法:

升级python到3.5.3版本或者最新

升级方式:

1)到下面网址下载python源码

https://www.python.org/ftp/python/

或者在本地执行

wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0rc2.tgz

2)解压以及编译python3.6

tar -xzvf Python-3.6.0rc2.tgz

cd Python-3.6.0rc2/

./configure

make

sudo make install

在导入pandas包的时候,

                   import pandas as pd

如果提示如下错误:

 

请安装pandas包,如下:

               pip install pandas --user -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

注意:使用pip安装包的时候,最好不要使用sudo方式。

如果安装过程中出现如下pip错误:

python3.6 -m ensurepip

sudo python3.6 -m pip install --upgrade pip

然后重新安装pandas

pip install pandas --user -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

执行成功,就重新执行:

python3.6

import pandas as pd

如果出现下面错误:

需要安装:

          sudo apt-get install liblzma-dev

然后回到Python-3.6.0rc2源码目录按照步骤2)重新编译python3.6:

 ./configure

make

sudo make install

以及重新import pandas包

如果无报错,就说明OK了。

然后继续执行:

df = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data', header=None)

df.tail()

如果没有报错,就可以正确看到导入的部分数据,如下:

因为接下来需要用到matplotlib 包,使用pip安装它:

sudo pip install matplotlib -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

matplotlib 是python的一个2D绘图库。

然后在python命令行导入matplotlib

import matplotlib.pyplot as plt

import numpy as np

注意:如果没有安装numpy包,可以使用如下命令安装:

sudo pip install numpy -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

在使用matplolib绘制图形时,如果提示如下错误:

请执行下面命令来安装依赖库:

sudo apt-get install tcl-dev tk-dev python-tk python3-tk

重新在python3.6源码目录编译python3.6<一定要从新编译python3.6可执行文件,否则还会报未配置错误>

然后在程序中导入:

import tkinter

这一次就可以正确导入了。

然后重新打开一个终端,依次执行刚才导入数据以及显示的步骤,如下:

如果没有错误发生,就可以正常显示这些数据绘制的图形了,如下:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值