<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. Verificação e correção dos imports:<jupyter_code>import os
#os.getcwd()
os.chdir('C:\\Users\\<NAME>\\Desktop\\sib_git\\si\\src')
from si.data import Dataset
from si.util import util
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)<jupyter_output><empty_output><jupyter_text>Seleção de 5 linhas e de todas as colunas (variável independente):<jupyter_code>dataset.X[:5, :]<jupyter_output><empty_output><jupyter_text>Cinco linhas de Y (variável dependente):<jupyter_code>dataset.Y[:5] 
print("Has label:", dataset.hasLabel())                 # verifica se tem variável dependente
print("Number of features:", dataset.getNumFeatures())  # Retorna o número de features, que neste caso são 9 colunas
print("Number of classes:", dataset.getNumClasses())    # Dá o número de labels
util.summary(dataset)
dataset.toDataframe()<jupyter_output><empty_output><jupyter_text>Standard Scaler<jupyter_code>from si.util import StandardScaler
sc = StandardScaler()
ds2 = sc.fit_transform(dataset)
util.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 Treshold<jupyter_code>#from si.data.feature_selection import VarianceThreshold<jupyter_output><empty_output><jupyter_text>Features em que a Variância é maior do que o threshold (8):<jupyter_code>vt = VarianceThreshold(8)
ds2 = vt.fit_transform(dataset)
util.summary(ds2)<jupyter_output><empty_output><jupyter_text>SelectKBest<jupyter_code># SelectKBest for classification
skb = SelectKBest(5, f_classification)
ds3 = skb.fit_transform(dataset)
util.summary(ds3)<jupyter_output><empty_output><jupyter_text>Clustering<jupyter_code>from si.unsupervised.Kmeans 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.PCA import PCA
pca = PCA(2, using='svd')
reduced = pca.fit_transform(iris)
print(pca.variance_explained())
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.knn import KNN
knn = KNN(3)
knn.fit(iris)
idx = 50
x = iris.X[idx, :]
pred = knn.predict(x)
print(f'Prediction: {pred}')
print(f'True: {iris.Y[idx]}')
print(knn.cost())<jupyter_output>Prediction: Iris-versicolor
True: Iris-versicolor
0.96
{'fraction_non_alphanumeric': 0.1347971095052807, 'fraction_numerical': 0.012229016120066704, 'mean_word_length': 7.95273631840796, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '55227', 'license': 'Apache-2.0', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1379, 'n_words': 250, 'path': 'scripts/eval1.ipynb', 'repo_name': 'MariaCout0/si', 'size': '3600'}