<jupyter_start><jupyter_text>***Limpieza de datos***<jupyter_code>print("Numero Filas y Columnas dataSet = ",dataSet.shape)
# Valores nulos en dataSet application
print("Valores nulos en dataSet credit:\n")
print(dataSet.isnull().sum())
# Valores del atributo doors
dataSet.doors.value_counts()
# Cambio tipo de variablde DOORS a string
dataSet.doors = dataSet.doors.astype(str)
# Cambia todo los "doors" de valor "5more" a 5
dataSet.doors = dataSet.doors.replace({'5more':5})
# Valores del atributo doors
dataSet.doors.value_counts()
# Valores del atributo persons
dataSet.persons.value_counts()
# Cambio tipo de variablde PERSONS a string
dataSet.persons = dataSet.persons.astype(str)
# Cambia todo los "doors" de valor "more" a 5
dataSet.persons = dataSet.persons.replace({'more':5})
# Valores del atributo persons
dataSet.persons.value_counts()<jupyter_output><empty_output><jupyter_text>***Cambiar atributos de Cualitativos Nominales A Cuantitativos Discretos***<jupyter_code># Valores de buying
dataSet.buying.value_counts()
# Reemplazar los valores
dictionary_replacement = {'low':1,
                          'med':2,
                          'high':3,
                          'vhigh':4}
dataSet.buying = dataSet.buying.map(dictionary_replacement)
# Valores de buying
dataSet.buying.value_counts()
# Valores de maint
dataSet.maint.value_counts()
# Reemplazar los valores
dictionary_replacement = {'low':1,
                          'med':2,
                          'high':3,
                          'vhigh':4}
dataSet.maint = dataSet.maint.map(dictionary_replacement)
# Valores de buying
dataSet.maint.value_counts()
# Valores de lug_boot
dataSet.lug_boot.value_counts()
# Reemplazar los valores
dictionary_replacement = {'small':1,
                          'med':2,
                          'big':3}
dataSet.lug_boot = dataSet.lug_boot.map(dictionary_replacement)
# Valores de buying
dataSet.lug_boot.value_counts()
# Valores de safety
dataSet.safety.value_counts()
# Reemplazar los valores
dictionary_replacement = {'low':1,
                          'med':2,
                          'high':3}
dataSet.safety = dataSet.safety.map(dictionary_replacement)
# Valores de buying
dataSet.safety.value_counts()
dataSet.head(n=5)
# Valores de la atributo "Class"
dataSet.Class.value_counts()<jupyter_output><empty_output><jupyter_text>***Splitting Data***<jupyter_code># Definir semilla y tamaño del conjuto de prueba
seed =123
test_size=0.2
# Se separa el atributo objetivo(target) en "y" y los demas atributos en "X"
X = dataSet.drop(['Class'],axis=1)
y = dataSet['Class']
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size = test_size, random_state = seed)<jupyter_output><empty_output><jupyter_text>***Máquinas de vectores de soporte***<jupyter_code>from sklearn.svm import SVC
clf = SVC(kernel='rbf')
#clf = SVC(kernel='linear')
#clf = SVC(kernel='poly')
#clf = SVC(kernel='sigmoid')
clf.fit(X_train, y_train)

# Predecir la respuesta para el conjunto de datos de prueba
y_pred = clf.predict(X_test)
# Resultados

print("Numero de datos en test:",X_test.shape[0])
print("Numero de aciertos:",metrics.accuracy_score(y_test,y_pred,normalize=False))
print("Numero de desaciertos:",(y_test != y_pred).sum())
print("Exactitud(Accuracy):",metrics.accuracy_score(y_test,y_pred))

# Matriz de Confución
print("\n\t---Matriz de Confución SVM---")
print(metrics.confusion_matrix(y_test,y_pred))<jupyter_output>Numero de datos en test: 346
Numero de aciertos: 328
Numero de desaciertos: 18
Exactitud(Accuracy): 0.9479768786127167

	---Matriz de Confución SVM---
[[ 80   0   4   0]
 [  2   9   0   2]
 [  9   0 228   0]
 [  1   0   0  11]]<jupyter_text>**Validacion Cruzada**<jupyter_code># Importarcion librerias
from sklearn.model_selection import KFold
from sklearn.model_selection import StratifiedKFold
from sklearn.model_selection import cross_val_score<jupyter_output><empty_output><jupyter_text>***KF***<jupyter_code>print("Accuracy with Splitting:",metrics.accuracy_score(y_test,y_pred),"\n")

for iteratorKF in range(5,11):
  kf = KFold(n_splits=iteratorKF,shuffle=True,random_state=seed)
  scores_cross = cross_val_score(clf, X, y, cv = kf)
  #Scores
  print("KF = ",kf.n_splits)  
  print("Accuracies with Cross Validation KF: ", scores_cross)
  print("Accuracy mean with Cross Validation KF: ", scores_cross.mean())
  print("\n")<jupyter_output>Accuracy with Splitting: 0.9479768786127167 

KF =  5
Accuracies with Cross Validation KF:  [0.94797688 0.96820809 0.93930636 0.93913043 0.95362319]
Accuracy mean with Cross Validation KF:  0.9496489905336348


KF =  6
Accuracies with Cross Validation KF:  [0.94444444 0.96180556 0.94444444 0.94444444 0.92361111 0.96527778]
Accuracy mean with Cross Validation KF:  0.9473379629629629


KF =  7
Accuracies with Cross Validation KF:  [0.94736842 0.95951417 0.94331984 0.94331984 0.95951417 0.91497976
 0.96341463]
Accuracy mean with Cross Validation KF:  0.9473472612111894


KF =  8
Accuracies with Cross Validation KF:  [0.94444444 0.95833333 0.97222222 0.93981481 0.94444444 0.95833333
 0.90740741 0.96759259]
Accuracy mean with Cross Validation KF:  0.9490740740740741


KF =  9
Accuracies with Cross Validation KF:  [0.953125   0.953125   0.97395833 0.953125   0.94270833 0.95833333
 0.9375     0.94270833 0.97395833]
Accuracy mean with Cross Validation KF:  0.9542824074074076


KF =  10
Accurac[...]<jupyter_text>***SKF***<jupyter_code>print("Accuracy with Splitting:",metrics.accuracy_score(y_test,y_pred),"\n")

for iteratorSKF in range(5,11):
  skf = StratifiedKFold(n_splits=iteratorSKF,shuffle=True,random_state=seed)
  scores_cross = cross_val_score(clf, X, y, cv = skf)
  #Scores
  print("KF = ",skf.n_splits)  
  print("Accuracies with Cross Validation SKF: ", scores_cross)
  print("Accuracy mean with Cross Validation SKF: ", scores_cross.mean())
  print("\n")<jupyter_output>Accuracy with Splitting: 0.9479768786127167 

KF =  5
Accuracies with Cross Validation SKF:  [0.9566474  0.96531792 0.94219653 0.95652174 0.94202899]
Accuracy mean with Cross Validation SKF:  0.9525425148697326


KF =  6
Accuracies with Cross Validation SKF:  [0.96875    0.95833333 0.93402778 0.95138889 0.96527778 0.94444444]
Accuracy mean with Cross Validation SKF:  0.9537037037037037


KF =  7
Accuracies with Cross Validation SKF:  [0.96356275 0.94736842 0.94331984 0.95546559 0.951417   0.94331984
 0.94308943]
Accuracy mean with Cross Validation SKF:  0.9496489817414079


KF =  8
Accuracies with Cross Validation SKF:  [0.96759259 0.94444444 0.9537037  0.94907407 0.9537037  0.9537037
 0.93518519 0.94907407]
Accuracy mean with Cross Validation SKF:  0.9508101851851852


KF =  9
Accuracies with Cross Validation SKF:  [0.96875    0.9375     0.97395833 0.953125   0.94791667 0.953125
 0.953125   0.92708333 0.94791667]
Accuracy mean with Cross Validation SKF:  0.9513888888888888


KF =  10
[...]
{'fraction_non_alphanumeric': 0.11023851076207097, 'fraction_numerical': 0.1301628853984875, 'mean_word_length': 4.457936507936508, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 8, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '219184', 'license': 'Unlicense', 'n_tokens_mistral': 3194, 'n_tokens_neox': 2626, 'n_words': 584, 'path': 'python/SVM&ValidacionCruzada-DataSet-CarEvaluation.ipynb', 'repo_name': 'JohamSMC/Electiva4', 'size': '6876'}