Apr-16-2017, 05:48 PM
(This post was last modified: Apr-16-2017, 07:10 PM by sparkz_alot.)
Classification by support vector method
Implement a method for solving the problem of classifying statistical data.
• visualize the initial data in the form of a scatter plot
• for a two-dimensional case with a linear separation of points, visualize the separating surface
• Display objects corresponding to the reference vectors.
So I realized a little but not all, help please
Implement a method for solving the problem of classifying statistical data.
• visualize the initial data in the form of a scatter plot
• for a two-dimensional case with a linear separation of points, visualize the separating surface
• Display objects corresponding to the reference vectors.
So I realized a little but not all, help please
import matplotlib.pyplot as plt
all_in = []
file = open('iris.docx', 'r') #Edgar Anderson's Iris Data (Iris.scv)
file_tmp = [line.strip() for line in file]
file.close()
fer = ''
temp = ''
for i in range(len(file_tmp)):
fer = file_tmp[i]
for j in range(len(fer)):
if j == (len(fer)-1):
temp+=fer[j]
all_in.append(temp)
temp = ''
elif fer[j] != ',':
temp+=fer[j]
elif fer[j] == ',':
all_in.append(temp)
temp = ''
fer = ''
Sepal.Length = []
Sepal.Width = []
Petal.Length = []
Petal.Width= []
Species = []
while True:
if all_in == []:
break
Sepal.Length.append(all_in[0])
Sepal.Width.append(all_in[1])
Petal.Length.append(all_in[2])
Petal.Width.append(all_in[3])
Species.append(all_in[4])
all_in.pop(0)
all_in.pop(0)
all_in.pop(0)
all_in.pop(0)
all_in.pop(0)
for i in range(len(Sepal.Length)):
temp = int(Sepal.Length[i])
Sepal.Length.pop(i)
Sepal.Length.insert(i, temp)
for i in range(len(Sepal.Width)):
temp = int(Sepal.Length[i])
Sepal.Width.pop(i)
Sepal.Width.insert(i, temp)
for i in range(len(Petal.Length)):
temp = int(Petal.Length[i])
Petal.Length.pop(i)
Petal.Length.insert(i, temp)
for i in range(len(Petal.Width)):
temp = int(Petal.Width[i])
Petal.Width.pop(i)
Petal.Width.insert(i, temp)
for i in range(len(Species)):
temp = int(Species[i])
Species.pop(i)
Species.insert(i, temp)
fig, ax = plt.subplots()
for color in ['red']:
ax.scatter(Sepal.Length, Petal.Length, c=color, label=color,
alpha=0.3, edgecolors='none')
ax.legend()
ax.grid(True)
plt.show()Moderator sparkz_alot:
Added code tags and removed formatting
