IIS_2023_1/antonov_dmitry_lab_4/lab4.py
DmitriyAntonov b855fc2dd4 реади
2023-10-08 14:15:58 +04:00

23 lines
689 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import pandas as pd
from sklearn.cluster import KMeans
from sklearn.manifold import TSNE
import matplotlib.pyplot as plt
# загрузка датасета
data = pd.read_csv('dataset.csv')
# выделение необходимых признаков
X = data[['Gender', 'International', 'GDP']]
# применение t-SNE для сокращения размерности
tsne = TSNE(n_components=2, random_state=42)
X_tsne = tsne.fit_transform(X)
# визуализация данных
plt.scatter(X_tsne[:, 0], X_tsne[:, 1], c=data['Target'], cmap='viridis')
plt.colorbar()
plt.xlabel('t-SNE х')
plt.ylabel('t-SNE у')
plt.title('t-SNE визуализация')
plt.show()