<jupyter_start><jupyter_text>Sistemas Inteligentes para Bioinformática Exemplos de validação de código. Deverá corrigir os imports e diretórios de acordo com a sua implementação.<jupyter_code>from si.data import Dataset, summary
import os
DIR = os.path.dirname(os.path.realpath('.'))
filename = os.path.join(DIR, 'datasets/breast-bin.data')<jupyter_output><empty_output><jupyter_text>Labeled dataset<jupyter_code>dataset = Dataset.from_data(filename, labeled=True)
dataset.X[:5, :]
dataset.Y[:5]
print("Has label:", dataset.hasLabel())
print("Number of features:", dataset.getNumFeatures())
print("Number of classes:", dataset.getNumClasses())
summary(dataset)
dataset.toDataframe()<jupyter_output><empty_output><jupyter_text>Standard Scaler<jupyter_code>from si.util.scale import StandardScaler
sc = StandardScaler()
ds2 = sc.fit_transform(dataset)
summary(ds2)<jupyter_output><empty_output><jupyter_text>Feature Selection<jupyter_code>from si.data.feature_selection import f_classification, selectKbest, VarianceThreshold<jupyter_output><empty_output><jupyter_text>Variance Threshold<jupyter_code>vt = VarianceThreshold(8)
ds2 = vt.fit_transform(dataset)
summary(ds2)<jupyter_output><empty_output><jupyter_text>SelectKBest<jupyter_code># SelectKBest for classification
skb = selectKbest(5, f_classification)
ds3 = skb.fit_transform(dataset)
summary(ds3)<jupyter_output><empty_output><jupyter_text>Clustering<jupyter_code>from si.unsupervised import Kmeans
import pandas as pd
import matplotlib.pyplot as plt
# o dataset iris nao estava inicialmente no github
filename = os.path.join(DIR, 'datasets/iris.data')
df = pd.read_csv(filename)
iris = Dataset.from_dataframe(df,ylabel="class")
# indice das features para o plot
c1 = 0
c2 = 1
# plot
plt.scatter(iris.X[:,c1], iris.X[:,c2])
plt.xlabel(iris._xnames[c1])
plt.ylabel(iris._xnames[c2])
plt.show()
kmeans = Kmeans(3)
cent, clust = kmeans.fit_transform(iris)

plt.scatter(iris.X[:,c1], iris.X[:,c2],c=clust)
plt.scatter(cent[:,c1],cent[:,c2], s = 100, c = 'black',marker='x')
plt.xlabel(iris._xnames[c1])
plt.ylabel(iris._xnames[c2])
plt.show()
# podem obter clusterings diferentes já que estes dependem da escolha dos centroids iniciais<jupyter_output><empty_output><jupyter_text>PCA<jupyter_code>from si.unsupervised import PCA
pca = PCA(2, PCA_type='svd')
reduced = pca.fit_transform(iris)
print(pca.explained_variances())
iris_pca = Dataset(reduced,iris.Y,xnames=['pc1','pc2'],yname='class')
iris_pca.toDataframe()
plt.scatter(iris_pca.X[:,0], iris_pca.X[:,1])
plt.xlabel("PC1")
plt.ylabel("PC2")
plt.show()<jupyter_output><empty_output><jupyter_text>KNN<jupyter_code>from si.util.util import train_test_split
from si.supervised import Knn

train_knn, test_knn = train_test_split(iris)
X_train, X_test, Y_train, Y_test = train_knn.X, test_knn.X, train_knn.Y, test_knn.Y

knn_test = Knn(5, classification=True)
knn_test.fit(Dataset(X=X_train, Y=Y_train))
y_pred = knn_test.predict(X_test)
knn_test.cost(y_pred, Y_test)<jupyter_output><empty_output><jupyter_text>Naive Bayes<jupyter_code>from si.supervised import GaussianNB as nb
filename = os.path.join(DIR, r'datasets\weather.data')
df_weather = pd.read_csv(filename)
weather = dataset.from_dataframe(df_weather, ylabel='play')

train_nb, test_nb = train_test_split(weather, split=0.7)
nb_weather = nb()
nb_weather.fit(train_nb)
nb_weather.predict(test_nb.X)
test_nb.Y
nb_weather.cost(test_nb.Y)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup