Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Task 1.3.1
- idk, something like that maybe
- !
- !
- !
- !
- V
- from matplotlib import pyplot as plt
- from mpl_toolkits.mplot3d import Axes3D
- import numpy as np
- dot1 = np.array([1.6,1.6,1.6])
- dot2 = np.array([2.1,2.1,2.1])
- dot3 = np.array([3.4,3.4,3.4])
- dot4 = np.array([5.2,5.2,5.2])
- print(np.linalg.norm(dot1-dot2-dot3-dot4))
- print(np.linalg.norm(dot1-dot2-dot3-dot4)**2)
- print(np.linalg.norm(dot1-dot2-dot3-dot4, ord=np.inf))
- print(np.linalg.norm(dot1-dot2-dot3-dot4, ord=1))
- fig = plt.figure()
- ax = fig.add_subplot(111, projection="3d")
- ax.scatter(1.6,1.6,1.6)
- ax.scatter(2.1,2.1,2.1)
- ax.scatter(3.4,3.4,3.4)
- ax.scatter(5.2,5.2,5.2)
- plt.show()
- #Task 2.3.1
- from matplotlib import pyplot as plt
- from sklearn.neighbors import KNeighborsClassifier
- from sklearn.model_selection import train_test_split
- from sklearn.metrics import accuracy_score
- import numpy as np
- import seaborn as sns
- iris = sns.load_dataset('iris')
- x_train, x_test, y_train, y_test = train_test_split(iris.iloc[:, :-1],
- iris.iloc[:, -1],
- test_size = 0.20) # просто поменять 0.20 на 0.15 (см второй пункт)
- model = KNeighborsClassifier(n_neighbors=3) # поменять 3 на 1/5/10
- model.fit(x_train, y_train)
- y_pred = model.predict(x_test)
- plt.figure(figsize=(10, 7))
- sns.scatterplot(x="petal_width",
- y = "petal_length",
- data=iris,
- hue='species',
- s=70)
- plt.xlabel("Длина лепестка, см")
- plt.ylabel("Ширина лепестка, см")
- plt.legend(loc=2)
- plt.grid()
- for i in range(len(y_test)):
- if np.array(y_test)[i] != y_pred[i]:
- plt.scatter(x_test.iloc[i, 3], x_test.iloc[i, 2], color="red", s=150)
- print(y_pred)
- print(f'accuracy: {accuracy_score(y_test, y_pred) :.3}')
- plt.show()
- Task 3.3.2
- from sklearn.feature_extraction import DictVectorizer
- traits = [{'adult': 3, 'child': 2},
- {'adult': 6, 'child': 4},
- {'adult': 1, 'teen': 3},
- {'adult': 2, 'teen': 1},
- ]
- dictvect = DictVectorizer(sparse=False)
- traits_matrix = dictvect.fit_transform(traits)
- print(traits_matrix)
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement