Skip to content

Commit

Permalink
Created using Colaboratory
Browse files Browse the repository at this point in the history
  • Loading branch information
rmaacario committed Dec 26, 2022
1 parent 348d00e commit f2a482a
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions A_Naive_Bayes_Classifier_of_Spatial_Prepositions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"colab": {
"private_outputs": true,
"provenance": [],
"authorship_tag": "ABX9TyOtAws7g+Ww5md7+Ng1v7T2",
"authorship_tag": "ABX9TyO/HriD8rlWF7QYjff37k8Q",
"include_colab_link": true
},
"kernelspec": {
Expand Down Expand Up @@ -380,7 +380,7 @@
{
"cell_type": "code",
"source": [
"# Split corpus into Train (80%) and Test (20%)\n",
"# Splits corpus into Train (80%) and Test (20%)\n",
"\n",
"from sklearn.model_selection import train_test_split\n",
"\n",
Expand Down Expand Up @@ -417,10 +417,8 @@
{
"cell_type": "code",
"source": [
"# Hora de classificar o conjunto de treinamento\n",
"\n",
"model = MultinomialNB() # Cria um objeto do tipo \"Classificador Bayesiano Multinomial\"\n",
"model.fit(X_train, y_train) # Busca ajustar os dados às etiquetas"
"model = MultinomialNB() # Creates MNB model\n",
"model.fit(X_train, y_train) # Adjests data according to the tags"
],
"metadata": {
"id": "tSQ06050QRWB"
Expand All @@ -442,7 +440,7 @@
{
"cell_type": "code",
"source": [
"predictions[:3] # Conferindo..."
"predictions[:3] "
],
"metadata": {
"id": "uHz4gI5LQW1P"
Expand All @@ -453,8 +451,7 @@
{
"cell_type": "code",
"source": [
"# Cálculo das métricas com sklearn\n",
"\n",
"# Using Scikit-learn\n",
"from sklearn.metrics import classification_report\n",
"\n",
"print(classification_report(y_test, predictions))"
Expand Down Expand Up @@ -514,8 +511,8 @@
{
"cell_type": "code",
"source": [
"# Probabilidades (prévia) das classes\n",
"# Muito útil, pois mostra o viés\n",
"# Probabilitues (prior) of classes\n",
"# Shows bias\n",
"\n",
"model.class_log_prior_"
],
Expand All @@ -539,7 +536,7 @@
{
"cell_type": "code",
"source": [
"# N. of atributes\n",
"# N. of attributes\n",
"\n",
"model.n_features_in_"
],
Expand All @@ -552,8 +549,8 @@
{
"cell_type": "code",
"source": [
"# Probabilidade posterior de cada atributo (logarítmica)\n",
"# A primeira lista corresponde à classe 0 (Negativo) e, a segunda, à classe 1 (Positivo)\n",
"# Post probability of each attribute (logarithmic)\n",
"# The first list corresponds to class 0 (Negative) and the second to class 1 (Positive)\n",
"\n",
"model.feature_log_prob_"
],
Expand All @@ -566,7 +563,7 @@
{
"cell_type": "code",
"source": [
"# Nomes dos atributos indexados alfabeticamente\n",
"# Alphabetically indexed attribute names\n",
"\n",
"vetor.get_feature_names_out()"
],
Expand Down Expand Up @@ -606,10 +603,7 @@
{
"cell_type": "code",
"source": [
"df['Ratio SPATIAL/NON-SPATIAL'] = df['SPATIAL'] / df['NON-SPATIAL'] \n",
"\n",
"# O DataFrame resultante poderá ser ordenado por \"espacialidade\" \n",
"# (como são números negativos, quanto menor a razão acima, mais \"epacial\")\n",
"df['Ratio SPATIAL/NON-SPATIAL'] = df['SPATIAL'] / df['NON-SPATIAL'] #The smaller the ratio, the more \"spatial\" is the term.\n",
"df"
],
"metadata": {
Expand Down

0 comments on commit f2a482a

Please sign in to comment.