Inzynierka/main.py

29 lines
873 B
Python
Raw Normal View History

2023-06-02 12:51:02 +02:00
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
2023-06-22 10:06:38 +02:00
from sklearn.svm import SVR
from sklearn import preprocessing
from sklearn import utils
2023-06-02 12:51:02 +02:00
2023-06-22 10:06:38 +02:00
data = pd.read_csv('starclusters-global-parameters2.dat',skiprows=1 ,delim_whitespace=True, header=None)
shuffled_data = data.sample(frac=1, random_state=42)
n = int(0.8 * len(shuffled_data))
data_train = shuffled_data[:n]
data_test = shuffled_data[n:]
X_train = data_train.iloc[:, 1:-1].values
y_train = data_train.iloc[:, -1].values
lab = preprocessing.LabelEncoder()
y_transformed = lab.fit_transform(y_train)
X_test = data_test.iloc[:, 1:-1].values
2023-06-02 12:51:02 +02:00
classifier = RandomForestClassifier()
2023-06-22 10:06:38 +02:00
classifier.fit(X_train, y_transformed)
2023-06-02 12:51:02 +02:00
y_pred = classifier.predict(X_test)
2023-06-22 17:33:26 +02:00
data_test['8'] = list(y_pred)
2023-06-23 09:12:07 +02:00
data_test.to_csv('prediction.dat', sep=' ', index=False)