pycharm 二分類

fxy詩錯亦染發表於2019-01-10
from numpy import *
import random
import numpy as np
from sklearn.cluster import KMeans
import re
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.colors
import csv
import pandas as pd
import imp

if __name__ == '__main__':
    mpl.rcParams['font.sans-serif'] = ['simHei']
    mpl.rcParams['axes.unicode_minus'] = False
    Mat = pd.read_csv("abo3.csv", sep=',', header=None)
    # print(Mat)
    Mat = mat(Mat)
    # print(avaMat)
    print(type(Mat))
    # li = Mat.tolist()
    # print(li)
    x1 = []
    y1 = []
    x2 = []
    y2 = []
    rows = shape(Mat)[0]
    for i in range(rows):
        print(Mat[i,7])
        if Mat[i,7] == '1':
            plt.scatter(float(Mat[i,2]),float(Mat[i,3]),c='r',marker='o')
            # x1.append(float(Mat[i,2]))
            # y1.append(float(Mat[i,3]))
            # print(x1)
            # plt.scatter(x1,y1)
        elif Mat[i,7] == '0':
            plt.scatter(float(Mat[i,2]),float(Mat[i,3]),c='b',marker='*')
    plt.show()
    同
from numpy import *
import random
import numpy as np
from sklearn.cluster import KMeans
import re
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.colors
import csv
import pandas as pd
import imp

if __name__ == '__main__':
    mpl.rcParams['font.sans-serif'] = ['simHei']
    mpl.rcParams['axes.unicode_minus'] = False
    Mat = pd.read_csv("abo3.csv", sep=',', header=None)
    # print(Mat)
    Mat = mat(Mat)
    # print(avaMat)
    print(type(Mat))
    # li = Mat.tolist()
    # print(li)
    x1 = []
    y1 = []
    x2 = []
    y2 = []
    rows = shape(Mat)[0]
    for i in range(rows):
        print(Mat[i, 7])
        if Mat[i, 7] == '1':
            # plt.scatter(float(Mat[i, 2]), float(Mat[i, 3]), c='r', marker='o')
            x1.append(float(Mat[i,2]))
            y1.append(float(Mat[i,3]))
            plt.scatter(x1,y1,c='r', marker='o')
        elif Mat[i, 7] == '0':
            x2.append(float(Mat[i, 2]))
            y2.append(float(Mat[i, 3]))
            plt.scatter(x2, y2, c='g', marker='*')
            # plt.scatter(float(Mat[i, 2]), float(Mat[i, 3]), c='b', marker='*')
    plt.xlabel('dA-O')
    plt.ylabel('dB-0')
    plt.show()
結果如圖:


 

 

相關文章