├── README.md ├── model.pkl.gz ├── requirements.txt ├── app.py ├── Streamlit Setup.ipynb ├── LICENSE └── Modelo_Nivelo.ipynb /README.md: -------------------------------------------------------------------------------- 1 | # modelo de machine learning e aplicação do Nivelo 2 | -------------------------------------------------------------------------------- /model.pkl.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luislauriano/nivelo/main/model.pkl.gz -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy>=1.9.2 2 | scipy>=0.15.1 3 | scikit-learn==1.3.2 4 | matplotlib>=1.4.3 5 | pandas>=0.19 6 | streamlit 7 | altair 8 | plotly 9 | xgboost 10 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import pandas as pd 3 | import pickle 4 | import gzip 5 | import plotly.express as px 6 | from xgboost import XGBClassifier 7 | 8 | # Carregamento do modelo 9 | with gzip.open('model.pkl.gz', 'rb') as f: 10 | model = pickle.load(f) 11 | 12 | # Função para preparar os dados de entrada 13 | def prepare_input(bncc_componente, acertos, possui_diagnostico_de_transtorno, turma, ano): 14 | # Ajustando os dados de entrada com base nas variáveis da sua tabela 15 | input_data = pd.DataFrame({ 16 | 'bncc_componente': [bncc_componente], 17 | 18 | 'faltas': [faltas], 19 | 'possui_diagnostico_de_transtorno': [possui_diagnostico_de_transtorno], 20 | 'turma': [turma] 21 | 22 | }) 23 | 24 | # Convertendo variáveis categóricas em variáveis dummy 25 | input_data = pd.get_dummies(input_data, columns=['bncc_componente', 'turma']) 26 | 27 | # Garantindo que as colunas do input_data correspondam ao modelo treinado 28 | model_columns = model.feature_names_in_ 29 | input_data = input_data.reindex(columns=model_columns, fill_value=0) 30 | 31 | return input_data 32 | 33 | # Carregar os dados do CSV (ajustar conforme seus dados reais) 34 | df = pd.read_csv('Dados_tratados.csv') 35 | 36 | # Calculando algumas métricas para exibição 37 | media_acertos = df['total_acertos'].mean() 38 | 39 | maior_acertos = df['total_acertos'].max() 40 | 41 | 42 | with st.container(): 43 | col4, col5 = st.columns(2) 44 | 45 | with col4: 46 | st.markdown( 47 | f""" 48 | 68 |
69 |
Média de Acertos:
70 |
{media_acertos:,.2f}
71 |
72 | """, 73 | unsafe_allow_html=True 74 | ) 75 | 76 | with col5: 77 | st.markdown( 78 | f""" 79 | 99 |
100 |
Maior Acerto:
101 |
{maior_acertos:,.2f}
102 |
103 | """, 104 | unsafe_allow_html=True 105 | ) 106 | 107 | col1, col2 = st.columns(2) 108 | 109 | with col1: 110 | # Exibir gráfico total de acertos por alunos 111 | grouped_data = df.groupby(['id_aluno'])['total_acertos'].sum()[:100] 112 | st.markdown( 113 | """ 114 | 122 |
123 | Acertos por Alunos 124 |
125 | """, 126 | unsafe_allow_html=True 127 | ) 128 | st.bar_chart(grouped_data) 129 | 130 | with col2: 131 | # Média de dificuldade acertos dos alunos 132 | grouped_data_dois = df.groupby('id_aluno')[['dificuldade_media_acertos']].sum()[:100] 133 | 134 | st.markdown( 135 | """ 136 | 144 |
145 | Média de dificuldade acertos dos alunos 146 |
147 | """, 148 | unsafe_allow_html=True 149 | ) 150 | st.area_chart(grouped_data_dois) 151 | 152 | col6, col7 = st.columns(2) 153 | 154 | with col6: 155 | # Taxa de acerto BNCC 156 | grouped_data_seis = df.groupby('id_aluno')[['taxa_acerto_EF06MA', 'taxa_acerto_EF07MA']].sum()[:10] 157 | st.markdown( 158 | """ 159 | 167 |
168 | Taxa de acerto BNCC 169 |
170 | """, 171 | unsafe_allow_html=True 172 | ) 173 | st.bar_chart(grouped_data_seis) 174 | 175 | with col7: 176 | # Gráfico de tempo de estudo médio por turma 177 | grouped_data_sete = df.groupby('dificuldade')[['acertou_EF06MA', 178 | 'acertou_EF07MA', 'acertou_EF08MA', 'acertou_EF09MA', 'acertou_EM13MA']].sum()[:10] 179 | st.markdown( 180 | """ 181 | 189 |
190 | Dificuldade com base nas BNCCs 191 |
192 | """, 193 | unsafe_allow_html=True 194 | ) 195 | st.bar_chart(grouped_data_sete) 196 | 197 | st.markdown( 198 | """ 199 | 217 |
218 | Insira as informações solicitadas abaixo para a previsão do modelo: 219 |
220 |
221 | Aqui você consegue prever a chance de um aluno possuir dificuldade ou não com base na prova de nivelamento aplicada, 222 | podendo assim entender melhor o perfil dos alunos
Resultado igual a 1 para quando o aluno pode possuir alguma dificuldade. 223 |
224 | """, 225 | unsafe_allow_html=True 226 | ) 227 | 228 | with st.container(): 229 | 230 | col1, col2 = st.columns(2) 231 | with col1: 232 | bncc_componente = st.selectbox('Selecione o código BNCC', ['EF06MA', 'EF07MA','EF08MA','EF09MA', 'EM13MA']) 233 | with col2: 234 | idade = st.slider('Idade do aluno', 3, 25) 235 | 236 | col4, col5 = st.columns(2) 237 | with col4: 238 | faltas = st.number_input('Quantidade de faltas', 0, 200, 25) 239 | with col5: 240 | possui_diagnostico_de_transtorno = st.selectbox('Possui diagnostico de algum transtorno', ['Sim', 'Não']) 241 | 242 | turma = st.selectbox('Selecione a Turma', ['EM','FM']) 243 | 244 | 245 | # Preparar os dados de entrada 246 | input_data = prepare_input(bncc_componente, idade, faltas, possui_diagnostico_de_transtorno, turma) 247 | 248 | try: 249 | if not input_data.empty: 250 | predicao = model.predict(input_data) 251 | st.write(f"Previsão se o aluno irá possui alguma dificuldade: {int(predicao[0])}") 252 | else: 253 | st.write("Não foi possível fazer a previsão devido a problemas com os dados de entrada.") 254 | except Exception as e: 255 | st.write(f"Erro ao fazer a previsão: {e}") 256 | 257 | st.markdown( 258 | """ 259 | 270 |
271 | Previsão de Dificuldade dos Alunos - Base de Dados 272 |
273 | """, 274 | unsafe_allow_html=True 275 | ) 276 | 277 | st.dataframe(df.head()) 278 | -------------------------------------------------------------------------------- /Streamlit Setup.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "Collecting streamlit\n", 13 | " Downloading streamlit-1.23.1-py2.py3-none-any.whl (8.9 MB)\n", 14 | "Requirement already satisfied: python-dateutil<3,>=2 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from streamlit) (2.8.1)\n", 15 | "Collecting pyarrow>=4.0\n", 16 | " Downloading pyarrow-12.0.1-cp37-cp37m-win_amd64.whl (21.5 MB)\n", 17 | "Collecting gitpython!=3.1.19,<4,>=3\n", 18 | " Downloading GitPython-3.1.40-py3-none-any.whl (190 kB)\n", 19 | "Collecting protobuf<5,>=3.20\n", 20 | " Downloading protobuf-4.24.4-cp37-cp37m-win_amd64.whl (430 kB)\n", 21 | "Requirement already satisfied: typing-extensions<5,>=4.0.1 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from streamlit) (4.3.0)\n", 22 | "Collecting toml<2\n", 23 | " Downloading toml-0.10.2-py2.py3-none-any.whl (16 kB)\n", 24 | "Collecting tenacity<9,>=8.0.0\n", 25 | " Downloading tenacity-8.2.3-py3-none-any.whl (24 kB)\n", 26 | "Requirement already satisfied: numpy<2,>=1 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from streamlit) (1.18.1)\n", 27 | "Collecting tzlocal<5,>=1.1\n", 28 | " Downloading tzlocal-4.3.1-py3-none-any.whl (20 kB)\n", 29 | "Requirement already satisfied: packaging<24,>=14.1 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from streamlit) (20.1)\n", 30 | "Collecting cachetools<6,>=4.0\n", 31 | " Downloading cachetools-5.3.2-py3-none-any.whl (9.3 kB)\n", 32 | "Requirement already satisfied: click<9,>=7.0 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from streamlit) (7.0)\n", 33 | "Requirement already satisfied: requests<3,>=2.4 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from streamlit) (2.22.0)\n", 34 | "Collecting pympler<2,>=0.9\n", 35 | " Downloading Pympler-1.0.1-py3-none-any.whl (164 kB)\n", 36 | "Collecting altair<6,>=4.0\n", 37 | " Downloading altair-5.0.1-py3-none-any.whl (471 kB)\n", 38 | "Collecting pydeck<1,>=0.1.dev5\n", 39 | " Downloading pydeck-0.8.1b0-py2.py3-none-any.whl (4.8 MB)\n", 40 | "Collecting blinker<2,>=1.0.0\n", 41 | " Downloading blinker-1.6.3-py3-none-any.whl (13 kB)\n", 42 | "Requirement already satisfied: rich<14,>=10.11.0 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from streamlit) (12.4.4)\n", 43 | "Collecting validators<1,>=0.2\n", 44 | " Downloading validators-0.20.0.tar.gz (30 kB)\n", 45 | "Requirement already satisfied: pandas<3,>=0.25 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from streamlit) (1.0.1)\n", 46 | "Requirement already satisfied: pillow<10,>=6.2.0 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from streamlit) (7.0.0)\n", 47 | "Requirement already satisfied: importlib-metadata<7,>=1.4 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from streamlit) (1.5.0)\n", 48 | "Requirement already satisfied: watchdog; platform_system != \"Darwin\" in c:\\users\\charu\\anaconda3\\lib\\site-packages (from streamlit) (0.10.2)\n", 49 | "Requirement already satisfied: tornado<7,>=6.0.3 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from streamlit) (6.0.3)\n", 50 | "Requirement already satisfied: six>=1.5 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from python-dateutil<3,>=2->streamlit) (1.14.0)\n", 51 | "Collecting gitdb<5,>=4.0.1\n", 52 | " Downloading gitdb-4.0.11-py3-none-any.whl (62 kB)\n", 53 | "Collecting pytz-deprecation-shim\n", 54 | " Downloading pytz_deprecation_shim-0.1.0.post0-py2.py3-none-any.whl (15 kB)\n", 55 | "Collecting tzdata; platform_system == \"Windows\"\n", 56 | " Downloading tzdata-2023.3-py2.py3-none-any.whl (341 kB)\n", 57 | "Collecting backports.zoneinfo; python_version < \"3.9\"\n", 58 | " Downloading backports.zoneinfo-0.2.1-cp37-cp37m-win_amd64.whl (38 kB)\n", 59 | "Requirement already satisfied: pyparsing>=2.0.2 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from packaging<24,>=14.1->streamlit) (2.4.6)\n", 60 | "Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1\n", 61 | " Using cached urllib3-1.25.11-py2.py3-none-any.whl (127 kB)\n", 62 | "Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from requests<3,>=2.4->streamlit) (3.0.4)\n", 63 | "Requirement already satisfied: idna<2.9,>=2.5 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from requests<3,>=2.4->streamlit) (2.8)\n", 64 | "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from requests<3,>=2.4->streamlit) (2019.11.28)\n", 65 | "Requirement already satisfied: jinja2 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from altair<6,>=4.0->streamlit) (2.11.1)\n", 66 | "Requirement already satisfied: toolz in c:\\users\\charu\\anaconda3\\lib\\site-packages (from altair<6,>=4.0->streamlit) (0.10.0)\n", 67 | "Requirement already satisfied: jsonschema>=3.0 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from altair<6,>=4.0->streamlit) (3.2.0)\n", 68 | "Requirement already satisfied: commonmark<0.10.0,>=0.9.0 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from rich<14,>=10.11.0->streamlit) (0.9.1)\n", 69 | "Requirement already satisfied: pygments<3.0.0,>=2.6.0 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from rich<14,>=10.11.0->streamlit) (2.12.0)\n", 70 | "Requirement already satisfied: decorator>=3.4.0 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from validators<1,>=0.2->streamlit) (4.4.1)\n", 71 | "Requirement already satisfied: pytz>=2017.2 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from pandas<3,>=0.25->streamlit) (2019.3)\n", 72 | "Requirement already satisfied: zipp>=0.5 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from importlib-metadata<7,>=1.4->streamlit) (2.2.0)\n", 73 | "Requirement already satisfied: pathtools>=0.1.1 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from watchdog; platform_system != \"Darwin\"->streamlit) (0.1.2)\n", 74 | "Collecting smmap<6,>=3.0.1\n", 75 | " Downloading smmap-5.0.1-py3-none-any.whl (24 kB)\n", 76 | "Requirement already satisfied: MarkupSafe>=0.23 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from jinja2->altair<6,>=4.0->streamlit) (1.1.1)\n", 77 | "Requirement already satisfied: setuptools in c:\\users\\charu\\anaconda3\\lib\\site-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit) (45.2.0.post20200210)\n", 78 | "Requirement already satisfied: pyrsistent>=0.14.0 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit) (0.15.7)\n", 79 | "Requirement already satisfied: attrs>=17.4.0 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit) (19.3.0)\n", 80 | "Building wheels for collected packages: validators\n", 81 | " Building wheel for validators (setup.py): started\n", 82 | " Building wheel for validators (setup.py): finished with status 'done'\n", 83 | " Created wheel for validators: filename=validators-0.20.0-py3-none-any.whl size=19570 sha256=3d65b684f55c87e4e446a6e8b9ae50d945ee3c52923a1d8e76c27cc22181953e\n", 84 | " Stored in directory: c:\\users\\charu\\appdata\\local\\pip\\cache\\wheels\\5f\\55\\ab\\36a76989f7f88d9ca7b1f68da6d94252bb6a8d6ad4f18e04e9\n", 85 | "Successfully built validators\n", 86 | "Installing collected packages: pyarrow, smmap, gitdb, gitpython, protobuf, toml, tenacity, tzdata, backports.zoneinfo, pytz-deprecation-shim, tzlocal, cachetools, pympler, altair, pydeck, blinker, validators, streamlit, urllib3\n", 87 | " Attempting uninstall: urllib3\n", 88 | " Found existing installation: urllib3 1.26.10\n", 89 | " Uninstalling urllib3-1.26.10:\n", 90 | " Successfully uninstalled urllib3-1.26.10\n", 91 | "Successfully installed altair-5.0.1 backports.zoneinfo-0.2.1 blinker-1.6.3 cachetools-5.3.2 gitdb-4.0.11 gitpython-3.1.40 protobuf-4.24.4 pyarrow-12.0.1 pydeck-0.8.1b0 pympler-1.0.1 pytz-deprecation-shim-0.1.0.post0 smmap-5.0.1 streamlit-1.23.1 tenacity-8.2.3 toml-0.10.2 tzdata-2023.3 tzlocal-4.3.1 urllib3-1.25.11 validators-0.20.0\n" 92 | ] 93 | }, 94 | { 95 | "name": "stderr", 96 | "output_type": "stream", 97 | "text": [ 98 | "ERROR: selenium 4.3.0 has requirement urllib3[secure,socks]~=1.26, but you'll have urllib3 1.25.11 which is incompatible.\n", 99 | "ERROR: huggingface-hub 0.8.1 has requirement packaging>=20.9, but you'll have packaging 20.1 which is incompatible.\n" 100 | ] 101 | } 102 | ], 103 | "source": [ 104 | "!pip install streamlit" 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": 2, 110 | "metadata": {}, 111 | "outputs": [ 112 | { 113 | "name": "stdout", 114 | "output_type": "stream", 115 | "text": [ 116 | "Collecting pipreqs\n", 117 | " Downloading pipreqs-0.4.13-py2.py3-none-any.whl (33 kB)\n", 118 | "Collecting yarg\n", 119 | " Downloading yarg-0.1.9-py2.py3-none-any.whl (19 kB)\n", 120 | "Processing c:\\users\\charu\\appdata\\local\\pip\\cache\\wheels\\72\\b0\\3f\\1d95f96ff986c7dfffe46ce2be4062f38ebd04b506c77c81b9\\docopt-0.6.2-py2.py3-none-any.whl\n", 121 | "Requirement already satisfied: requests in c:\\users\\charu\\anaconda3\\lib\\site-packages (from yarg->pipreqs) (2.22.0)\n", 122 | "Requirement already satisfied: idna<2.9,>=2.5 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from requests->yarg->pipreqs) (2.8)\n", 123 | "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from requests->yarg->pipreqs) (1.25.11)\n", 124 | "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from requests->yarg->pipreqs) (2019.11.28)\n", 125 | "Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\\users\\charu\\anaconda3\\lib\\site-packages (from requests->yarg->pipreqs) (3.0.4)\n", 126 | "Installing collected packages: yarg, docopt, pipreqs\n", 127 | "Successfully installed docopt-0.6.2 pipreqs-0.4.13 yarg-0.1.9\n" 128 | ] 129 | } 130 | ], 131 | "source": [ 132 | "!pip install pipreqs" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 7, 138 | "metadata": {}, 139 | "outputs": [ 140 | { 141 | "name": "stderr", 142 | "output_type": "stream", 143 | "text": [ 144 | "INFO: Successfully saved requirements file in C:\\Users\\charu\\Charu\\GitProjects\\MLDeploymentUsingStreamlit\\requirements.txt\n" 145 | ] 146 | } 147 | ], 148 | "source": [ 149 | "!pipreqs" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 6, 155 | "metadata": {}, 156 | "outputs": [ 157 | { 158 | "name": "stderr", 159 | "output_type": "stream", 160 | "text": [ 161 | "INFO: Successfully saved requirements file in C:\\Users\\charu\\Charu\\GitProjects\\MLDeploymentUsingStreamlit\\requirements.txt\n" 162 | ] 163 | } 164 | ], 165 | "source": [ 166 | "!pipreqs --force" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": null, 172 | "metadata": {}, 173 | "outputs": [], 174 | "source": [] 175 | } 176 | ], 177 | "metadata": { 178 | "kernelspec": { 179 | "display_name": "Python 3", 180 | "language": "python", 181 | "name": "python3" 182 | }, 183 | "language_info": { 184 | "codemirror_mode": { 185 | "name": "ipython", 186 | "version": 3 187 | }, 188 | "file_extension": ".py", 189 | "mimetype": "text/x-python", 190 | "name": "python", 191 | "nbconvert_exporter": "python", 192 | "pygments_lexer": "ipython3", 193 | "version": "3.7.6" 194 | } 195 | }, 196 | "nbformat": 4, 197 | "nbformat_minor": 4 198 | } 199 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Modelo_Nivelo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [] 7 | }, 8 | "kernelspec": { 9 | "name": "python3", 10 | "display_name": "Python 3" 11 | }, 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "code", 19 | "execution_count": 282, 20 | "metadata": { 21 | "id": "sZTzFan1qDMz" 22 | }, 23 | "outputs": [], 24 | "source": [ 25 | "import pandas as pd\n", 26 | "import numpy as np\n", 27 | "from sklearn.model_selection import train_test_split\n", 28 | "from xgboost import XGBClassifier" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "source": [ 34 | "df = pd.read_csv('dados_prova_nivelo.csv')" 35 | ], 36 | "metadata": { 37 | "id": "-sdfgDl2qQdc" 38 | }, 39 | "execution_count": 283, 40 | "outputs": [] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "source": [ 45 | "df.head()" 46 | ], 47 | "metadata": { 48 | "colab": { 49 | "base_uri": "https://localhost:8080/", 50 | "height": 255 51 | }, 52 | "id": "5zhjQ8-KrmKd", 53 | "outputId": "d1c402d4-6139-4fb9-e287-a492b06d1a8a" 54 | }, 55 | "execution_count": 284, 56 | "outputs": [ 57 | { 58 | "output_type": "execute_result", 59 | "data": { 60 | "text/plain": [ 61 | " id_aluno bncc_questao_1 acertou_questao_1 bncc_questao_2 \\\n", 62 | "0 1 EF06MA03 1 EF07MA11 \n", 63 | "1 2 EF06MA03 0 EF07MA11 \n", 64 | "2 3 EF06MA03 1 EF07MA11 \n", 65 | "3 4 EF06MA03 0 EF07MA11 \n", 66 | "4 5 EF06MA03 1 EF07MA11 \n", 67 | "\n", 68 | " acertou_questao_2 bncc_questao_3 acertou_questao_3 bncc_questao_4 \\\n", 69 | "0 1 EF08MA12 1 EF09MA06 \n", 70 | "1 1 EF08MA12 0 EF09MA06 \n", 71 | "2 0 EF08MA12 0 EF09MA06 \n", 72 | "3 0 EF08MA12 1 EF09MA06 \n", 73 | "4 1 EF08MA12 0 EF09MA06 \n", 74 | "\n", 75 | " acertou_questao_4 bncc_questao_5 ... bncc_questao_7 acertou_questao_7 \\\n", 76 | "0 1 EM13MAT101 ... EF06MA08 1 \n", 77 | "1 1 EM13MAT101 ... EF06MA08 0 \n", 78 | "2 1 EM13MAT101 ... EF06MA08 0 \n", 79 | "3 0 EM13MAT101 ... EF06MA08 0 \n", 80 | "4 0 EM13MAT101 ... EF06MA08 1 \n", 81 | "\n", 82 | " bncc_questao_8 acertou_questao_8 bncc_questao_9 acertou_questao_9 \\\n", 83 | "0 EF07MA05 0 EF09MA08 1 \n", 84 | "1 EF07MA05 1 EF09MA08 0 \n", 85 | "2 EF07MA05 0 EF09MA08 0 \n", 86 | "3 EF07MA05 0 EF09MA08 1 \n", 87 | "4 EF07MA05 0 EF09MA08 0 \n", 88 | "\n", 89 | " bncc_questao_10 acertou_questao_10 nota_final dificuldade \n", 90 | "0 EM13MAT303 1 9 0 \n", 91 | "1 EM13MAT303 1 5 1 \n", 92 | "2 EM13MAT303 0 4 1 \n", 93 | "3 EM13MAT303 0 3 1 \n", 94 | "4 EM13MAT303 0 4 1 \n", 95 | "\n", 96 | "[5 rows x 23 columns]" 97 | ], 98 | "text/html": [ 99 | "\n", 100 | "
\n", 101 | "
\n", 102 | "\n", 115 | "\n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | " \n", 226 | " \n", 227 | " \n", 228 | " \n", 229 | " \n", 230 | " \n", 231 | " \n", 232 | " \n", 233 | " \n", 234 | " \n", 235 | " \n", 236 | " \n", 237 | " \n", 238 | " \n", 239 | " \n", 240 | " \n", 241 | " \n", 242 | " \n", 243 | " \n", 244 | " \n", 245 | " \n", 246 | " \n", 247 | " \n", 248 | " \n", 249 | " \n", 250 | " \n", 251 | " \n", 252 | " \n", 253 | " \n", 254 | " \n", 255 | " \n", 256 | " \n", 257 | " \n", 258 | " \n", 259 | " \n", 260 | " \n", 261 | " \n", 262 | " \n", 263 | " \n", 264 | "
id_alunobncc_questao_1acertou_questao_1bncc_questao_2acertou_questao_2bncc_questao_3acertou_questao_3bncc_questao_4acertou_questao_4bncc_questao_5...bncc_questao_7acertou_questao_7bncc_questao_8acertou_questao_8bncc_questao_9acertou_questao_9bncc_questao_10acertou_questao_10nota_finaldificuldade
01EF06MA031EF07MA111EF08MA121EF09MA061EM13MAT101...EF06MA081EF07MA050EF09MA081EM13MAT303190
12EF06MA030EF07MA111EF08MA120EF09MA061EM13MAT101...EF06MA080EF07MA051EF09MA080EM13MAT303151
23EF06MA031EF07MA110EF08MA120EF09MA061EM13MAT101...EF06MA080EF07MA050EF09MA080EM13MAT303041
34EF06MA030EF07MA110EF08MA121EF09MA060EM13MAT101...EF06MA080EF07MA050EF09MA081EM13MAT303031
45EF06MA031EF07MA111EF08MA120EF09MA060EM13MAT101...EF06MA081EF07MA050EF09MA080EM13MAT303041
\n", 265 | "

5 rows × 23 columns

\n", 266 | "
\n", 267 | "
\n", 268 | "\n", 269 | "
\n", 270 | " \n", 278 | "\n", 279 | " \n", 319 | "\n", 320 | " \n", 344 | "
\n", 345 | "\n", 346 | "\n", 347 | "
\n", 348 | " \n", 359 | "\n", 360 | "\n", 449 | "\n", 450 | " \n", 472 | "
\n", 473 | "\n", 474 | "
\n", 475 | "
\n" 476 | ], 477 | "application/vnd.google.colaboratory.intrinsic+json": { 478 | "type": "dataframe", 479 | "variable_name": "df" 480 | } 481 | }, 482 | "metadata": {}, 483 | "execution_count": 284 484 | } 485 | ] 486 | }, 487 | { 488 | "cell_type": "markdown", 489 | "source": [ 490 | "## Engenharia de variaveis" 491 | ], 492 | "metadata": { 493 | "id": "TmrRuBZ62LRo" 494 | } 495 | }, 496 | { 497 | "cell_type": "code", 498 | "source": [ 499 | "# Transformando o DataFrame para o formato longo (melted)\n", 500 | "bncc_cols = [col for col in df.columns if 'bncc_questao' in col]\n", 501 | "acerto_cols = [col for col in df.columns if 'acertou_questao' in col]\n", 502 | "\n", 503 | "# Transformação para um DataFrame long com prefixo BNCC e acerto correspondente\n", 504 | "bncc_melted = df.melt(id_vars=['id_aluno'], value_vars=bncc_cols, var_name='questao', value_name='bncc_prefixo')\n", 505 | "acerto_melted = df.melt(id_vars=['id_aluno'], value_vars=acerto_cols, var_name='questao', value_name='acertou')\n", 506 | "\n", 507 | "# Removendo o sufixo '_questao_x' das colunas \"questao\" para combinar as duas tabelas\n", 508 | "bncc_melted['questao'] = bncc_melted['questao'].str.replace('bncc_questao_', '')\n", 509 | "acerto_melted['questao'] = acerto_melted['questao'].str.replace('acertou_questao_', '')\n", 510 | "\n", 511 | "# Juntando os DataFrames de prefixo e acerto\n", 512 | "df_long = pd.merge(bncc_melted, acerto_melted, on=['id_aluno', 'questao'])\n", 513 | "\n", 514 | "# Extraindo o prefixo de cada questão\n", 515 | "df_long['bncc_prefixo'] = df_long['bncc_prefixo'].str[:6]\n", 516 | "\n", 517 | "# Calculando a taxa de acerto por prefixo\n", 518 | "taxa_acerto_por_prefixo = (\n", 519 | " df_long.groupby(['id_aluno', 'bncc_prefixo'])['acertou']\n", 520 | " .mean()\n", 521 | " .unstack(fill_value=0)\n", 522 | " .add_prefix('taxa_acerto_')\n", 523 | ")\n", 524 | "\n", 525 | "# Unindo as taxas de acerto com o DataFrame original\n", 526 | "df = df.join(taxa_acerto_por_prefixo, on='id_aluno')\n" 527 | ], 528 | "metadata": { 529 | "id": "GvqosAMTPZZr" 530 | }, 531 | "execution_count": 285, 532 | "outputs": [] 533 | }, 534 | { 535 | "cell_type": "code", 536 | "source": [ 537 | "df.shape" 538 | ], 539 | "metadata": { 540 | "colab": { 541 | "base_uri": "https://localhost:8080/" 542 | }, 543 | "id": "boqWVQpWoCI2", 544 | "outputId": "28e35222-3830-4ee8-e6f8-16f490f5318e" 545 | }, 546 | "execution_count": 286, 547 | "outputs": [ 548 | { 549 | "output_type": "execute_result", 550 | "data": { 551 | "text/plain": [ 552 | "(50000, 28)" 553 | ] 554 | }, 555 | "metadata": {}, 556 | "execution_count": 286 557 | } 558 | ] 559 | }, 560 | { 561 | "cell_type": "code", 562 | "source": [ 563 | "# Calculando a taxa de acerto por prefixo\n", 564 | "acerto_por_prefixo = (\n", 565 | " df_long.groupby(['id_aluno','bncc_prefixo'])['acertou'].sum()\n", 566 | " .unstack(fill_value=0)\n", 567 | " .add_prefix('acertou_')\n", 568 | ")\n" 569 | ], 570 | "metadata": { 571 | "id": "2yfqxcG9oAXA" 572 | }, 573 | "execution_count": 287, 574 | "outputs": [] 575 | }, 576 | { 577 | "cell_type": "code", 578 | "source": [ 579 | "# Unindo as taxas de acerto com o DataFrame original\n", 580 | "df = df.join(acerto_por_prefixo, on='id_aluno')" 581 | ], 582 | "metadata": { 583 | "id": "IqwerYeXoTXB" 584 | }, 585 | "execution_count": 288, 586 | "outputs": [] 587 | }, 588 | { 589 | "cell_type": "code", 590 | "source": [ 591 | "# 2. Total de acertos e erros\n", 592 | "acertos_cols = df.filter(like=\"acertou_questao\")\n", 593 | "df['total_acertos'] = acertos_cols.sum(axis=1)\n", 594 | "df['total_erros'] = (acertos_cols == 0).sum(axis=1)\n", 595 | "\n", 596 | "# 3. Taxa de acerto geral\n", 597 | "df['taxa_acerto_geral'] = df['total_acertos'] / acertos_cols.shape[1]\n", 598 | "\n", 599 | "# 4. Dificuldade relativa das questões\n", 600 | "df['dificuldade_media_acertos'] = df['dificuldade'] / df['total_acertos'].replace(0, 1)\n", 601 | "\n", 602 | "# 5. Peso de cada acerto na nota final\n", 603 | "df['peso_acerto'] = df['nota_final'] / df['total_acertos'].replace(0, 1)\n", 604 | "\n", 605 | "# 6. Agrupamento de questões por dificuldade\n", 606 | "# (Supondo que as questões 1, 2 sejam as mais faceis, questoes 3 e 4 nivel medio e 5 e 6 questoes de BNCCs mais dificeis)\n", 607 | "df['taxa_acerto_facil'] = df[['acertou_questao_1', 'acertou_questao_2']].mean(axis=1)\n", 608 | "df['taxa_acerto_medio'] = df[['acertou_questao_3', 'acertou_questao_4']].mean(axis=1)\n", 609 | "df['taxa_acerto_dificil'] = df[['acertou_questao_5', 'acertou_questao_6', 'acertou_questao_7']].mean(axis=1)\n", 610 | "\n", 611 | "\n", 612 | "# 8. Combinações de acertos por áreas relacionadas\n", 613 | "# Por exemplo, combinando questões de matemática EF06MA e EF07MA\n", 614 | "df['taxa_acerto_EF06_EF07'] = df[['acertou_questao_1', 'acertou_questao_2', 'acertou_questao_6', 'acertou_questao_7']].mean(axis=1)\n", 615 | "\n" 616 | ], 617 | "metadata": { 618 | "id": "1UmoaRtePkJa" 619 | }, 620 | "execution_count": 289, 621 | "outputs": [] 622 | }, 623 | { 624 | "cell_type": "code", 625 | "source": [ 626 | "df.columns" 627 | ], 628 | "metadata": { 629 | "colab": { 630 | "base_uri": "https://localhost:8080/" 631 | }, 632 | "id": "CXnLZssGRyYz", 633 | "outputId": "90989ad4-9a69-40fe-db73-e44443825313" 634 | }, 635 | "execution_count": 290, 636 | "outputs": [ 637 | { 638 | "output_type": "execute_result", 639 | "data": { 640 | "text/plain": [ 641 | "Index(['id_aluno', 'bncc_questao_1', 'acertou_questao_1', 'bncc_questao_2',\n", 642 | " 'acertou_questao_2', 'bncc_questao_3', 'acertou_questao_3',\n", 643 | " 'bncc_questao_4', 'acertou_questao_4', 'bncc_questao_5',\n", 644 | " 'acertou_questao_5', 'bncc_questao_6', 'acertou_questao_6',\n", 645 | " 'bncc_questao_7', 'acertou_questao_7', 'bncc_questao_8',\n", 646 | " 'acertou_questao_8', 'bncc_questao_9', 'acertou_questao_9',\n", 647 | " 'bncc_questao_10', 'acertou_questao_10', 'nota_final', 'dificuldade',\n", 648 | " 'taxa_acerto_EF06MA', 'taxa_acerto_EF07MA', 'taxa_acerto_EF08MA',\n", 649 | " 'taxa_acerto_EF09MA', 'taxa_acerto_EM13MA', 'acertou_EF06MA',\n", 650 | " 'acertou_EF07MA', 'acertou_EF08MA', 'acertou_EF09MA', 'acertou_EM13MA',\n", 651 | " 'total_acertos', 'total_erros', 'taxa_acerto_geral',\n", 652 | " 'dificuldade_media_acertos', 'peso_acerto', 'taxa_acerto_facil',\n", 653 | " 'taxa_acerto_medio', 'taxa_acerto_dificil', 'taxa_acerto_EF06_EF07'],\n", 654 | " dtype='object')" 655 | ] 656 | }, 657 | "metadata": {}, 658 | "execution_count": 290 659 | } 660 | ] 661 | }, 662 | { 663 | "cell_type": "markdown", 664 | "source": [ 665 | "## Modelo" 666 | ], 667 | "metadata": { 668 | "id": "SD2TlRxd1oZW" 669 | } 670 | }, 671 | { 672 | "cell_type": "code", 673 | "source": [ 674 | "from sklearn.ensemble import RandomForestClassifier" 675 | ], 676 | "metadata": { 677 | "id": "v0Qq-yePWlue" 678 | }, 679 | "execution_count": 291, 680 | "outputs": [] 681 | }, 682 | { 683 | "cell_type": "code", 684 | "source": [ 685 | "df['dificuldade'].value_counts()" 686 | ], 687 | "metadata": { 688 | "colab": { 689 | "base_uri": "https://localhost:8080/", 690 | "height": 178 691 | }, 692 | "id": "hpZ_x6MgVC8J", 693 | "outputId": "750d5ac6-382e-4e29-bd23-e3c546912568" 694 | }, 695 | "execution_count": 292, 696 | "outputs": [ 697 | { 698 | "output_type": "execute_result", 699 | "data": { 700 | "text/plain": [ 701 | "dificuldade\n", 702 | "1 41446\n", 703 | "0 8554\n", 704 | "Name: count, dtype: int64" 705 | ], 706 | "text/html": [ 707 | "
\n", 708 | "\n", 721 | "\n", 722 | " \n", 723 | " \n", 724 | " \n", 725 | " \n", 726 | " \n", 727 | " \n", 728 | " \n", 729 | " \n", 730 | " \n", 731 | " \n", 732 | " \n", 733 | " \n", 734 | " \n", 735 | " \n", 736 | " \n", 737 | " \n", 738 | " \n", 739 | " \n", 740 | " \n", 741 | " \n", 742 | "
count
dificuldade
141446
08554
\n", 743 | "

" 744 | ] 745 | }, 746 | "metadata": {}, 747 | "execution_count": 292 748 | } 749 | ] 750 | }, 751 | { 752 | "cell_type": "code", 753 | "source": [ 754 | "df = pd.get_dummies(df, columns=['bncc_questao_1', 'bncc_questao_2', 'bncc_questao_3',\n", 755 | " 'bncc_questao_4', 'bncc_questao_5', 'bncc_questao_6',\n", 756 | " 'bncc_questao_7', 'bncc_questao_8', 'bncc_questao_9',\n", 757 | " 'bncc_questao_10'])" 758 | ], 759 | "metadata": { 760 | "id": "FXKbhqYxXgAp" 761 | }, 762 | "execution_count": 294, 763 | "outputs": [] 764 | }, 765 | { 766 | "cell_type": "code", 767 | "source": [ 768 | "df.columns" 769 | ], 770 | "metadata": { 771 | "colab": { 772 | "base_uri": "https://localhost:8080/" 773 | }, 774 | "id": "mCS02auSXg3c", 775 | "outputId": "bca48295-7e31-499f-debe-1a2d9a4c3ae0" 776 | }, 777 | "execution_count": 295, 778 | "outputs": [ 779 | { 780 | "output_type": "execute_result", 781 | "data": { 782 | "text/plain": [ 783 | "Index(['id_aluno', 'acertou_questao_1', 'acertou_questao_2',\n", 784 | " 'acertou_questao_3', 'acertou_questao_4', 'acertou_questao_5',\n", 785 | " 'acertou_questao_6', 'acertou_questao_7', 'acertou_questao_8',\n", 786 | " 'acertou_questao_9', 'acertou_questao_10', 'nota_final', 'dificuldade',\n", 787 | " 'taxa_acerto_EF06MA', 'taxa_acerto_EF07MA', 'taxa_acerto_EF08MA',\n", 788 | " 'taxa_acerto_EF09MA', 'taxa_acerto_EM13MA', 'acertou_EF06MA',\n", 789 | " 'acertou_EF07MA', 'acertou_EF08MA', 'acertou_EF09MA', 'acertou_EM13MA',\n", 790 | " 'total_acertos', 'total_erros', 'taxa_acerto_geral',\n", 791 | " 'dificuldade_media_acertos', 'peso_acerto', 'taxa_acerto_facil',\n", 792 | " 'taxa_acerto_medio', 'taxa_acerto_dificil', 'taxa_acerto_EF06_EF07',\n", 793 | " 'bncc_questao_1_EF06MA03', 'bncc_questao_2_EF07MA11',\n", 794 | " 'bncc_questao_3_EF08MA12', 'bncc_questao_4_EF09MA06',\n", 795 | " 'bncc_questao_5_EM13MAT101', 'bncc_questao_6_EM13MAT202',\n", 796 | " 'bncc_questao_7_EF06MA08', 'bncc_questao_8_EF07MA05',\n", 797 | " 'bncc_questao_9_EF09MA08', 'bncc_questao_10_EM13MAT303'],\n", 798 | " dtype='object')" 799 | ] 800 | }, 801 | "metadata": {}, 802 | "execution_count": 295 803 | } 804 | ] 805 | }, 806 | { 807 | "cell_type": "code", 808 | "source": [ 809 | "df['idade'] = np.random.randint(5, 25, size=len(df))" 810 | ], 811 | "metadata": { 812 | "id": "m6yzSc9H8H8z" 813 | }, 814 | "execution_count": 299, 815 | "outputs": [] 816 | }, 817 | { 818 | "cell_type": "code", 819 | "source": [ 820 | "df['Quantidade_faltas'] = np.random.randint(0, 50, size=len(df))" 821 | ], 822 | "metadata": { 823 | "id": "zqMWo0bq9UVI" 824 | }, 825 | "execution_count": 307, 826 | "outputs": [] 827 | }, 828 | { 829 | "cell_type": "code", 830 | "source": [ 831 | "df['possui_diagnostico_de_transtorno'] = np.random.choice([0, 1], size=len(df))" 832 | ], 833 | "metadata": { 834 | "id": "D7ICWoTl9d2T" 835 | }, 836 | "execution_count": 310, 837 | "outputs": [] 838 | }, 839 | { 840 | "cell_type": "code", 841 | "source": [ 842 | "df['turma'] = np.random.choice(['EM', 'FM'], size=len(df))" 843 | ], 844 | "metadata": { 845 | "id": "495qeUgw8RjF" 846 | }, 847 | "execution_count": 302, 848 | "outputs": [] 849 | }, 850 | { 851 | "cell_type": "markdown", 852 | "source": [ 853 | "EM = Ensino Médio\n", 854 | "FM = Fundamendal" 855 | ], 856 | "metadata": { 857 | "id": "nFFj_17V8p2E" 858 | } 859 | }, 860 | { 861 | "cell_type": "code", 862 | "source": [ 863 | "df['turma'] = df['turma'].map({'EM': 0, 'FM': 1})" 864 | ], 865 | "metadata": { 866 | "id": "ll6vdALa8kDN" 867 | }, 868 | "execution_count": 304, 869 | "outputs": [] 870 | }, 871 | { 872 | "cell_type": "code", 873 | "source": [ 874 | "X = df[['idade', 'turma','possui_diagnostico_de_transtorno', 'Quantidade_faltas'\n", 875 | " ]]\n", 876 | "\n", 877 | "y = df['dificuldade']\n", 878 | "\n", 879 | "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)\n", 880 | "\n", 881 | "model = XGBClassifier()\n", 882 | "rfc = RandomForestClassifier(random_state=35)\n", 883 | "\n", 884 | "model.fit(X_train, y_train)" 885 | ], 886 | "metadata": { 887 | "colab": { 888 | "base_uri": "https://localhost:8080/", 889 | "height": 254 890 | }, 891 | "id": "gTA9HfcVqR8k", 892 | "outputId": "ae4aa941-6f11-4776-a7e6-3e92bbbb2089" 893 | }, 894 | "execution_count": 311, 895 | "outputs": [ 896 | { 897 | "output_type": "execute_result", 898 | "data": { 899 | "text/plain": [ 900 | "XGBClassifier(base_score=None, booster=None, callbacks=None,\n", 901 | " colsample_bylevel=None, colsample_bynode=None,\n", 902 | " colsample_bytree=None, device=None, early_stopping_rounds=None,\n", 903 | " enable_categorical=False, eval_metric=None, feature_types=None,\n", 904 | " gamma=None, grow_policy=None, importance_type=None,\n", 905 | " interaction_constraints=None, learning_rate=None, max_bin=None,\n", 906 | " max_cat_threshold=None, max_cat_to_onehot=None,\n", 907 | " max_delta_step=None, max_depth=None, max_leaves=None,\n", 908 | " min_child_weight=None, missing=nan, monotone_constraints=None,\n", 909 | " multi_strategy=None, n_estimators=None, n_jobs=None,\n", 910 | " num_parallel_tree=None, random_state=None, ...)" 911 | ], 912 | "text/html": [ 913 | "
XGBClassifier(base_score=None, booster=None, callbacks=None,\n",
1318 |               "              colsample_bylevel=None, colsample_bynode=None,\n",
1319 |               "              colsample_bytree=None, device=None, early_stopping_rounds=None,\n",
1320 |               "              enable_categorical=False, eval_metric=None, feature_types=None,\n",
1321 |               "              gamma=None, grow_policy=None, importance_type=None,\n",
1322 |               "              interaction_constraints=None, learning_rate=None, max_bin=None,\n",
1323 |               "              max_cat_threshold=None, max_cat_to_onehot=None,\n",
1324 |               "              max_delta_step=None, max_depth=None, max_leaves=None,\n",
1325 |               "              min_child_weight=None, missing=nan, monotone_constraints=None,\n",
1326 |               "              multi_strategy=None, n_estimators=None, n_jobs=None,\n",
1327 |               "              num_parallel_tree=None, random_state=None, ...)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" 1338 | ] 1339 | }, 1340 | "metadata": {}, 1341 | "execution_count": 311 1342 | } 1343 | ] 1344 | }, 1345 | { 1346 | "cell_type": "code", 1347 | "source": [], 1348 | "metadata": { 1349 | "id": "m_EsHSaOSa6Z" 1350 | }, 1351 | "execution_count": 311, 1352 | "outputs": [] 1353 | }, 1354 | { 1355 | "cell_type": "code", 1356 | "source": [ 1357 | "from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score\n", 1358 | "\n", 1359 | "\n", 1360 | "y_pred = model.predict(X_test)\n", 1361 | "\n", 1362 | "\n", 1363 | "# Calculando as métricas\n", 1364 | "accuracy = accuracy_score(y_test, y_pred)\n", 1365 | "precision = precision_score(y_test, y_pred)\n", 1366 | "recall = recall_score(y_test, y_pred)\n", 1367 | "f1 = f1_score(y_test, y_pred)\n", 1368 | "\n", 1369 | "\n", 1370 | "print(f\"Accuracy: {accuracy}\")\n", 1371 | "print(f\"Precision (Weighted): {precision}\")\n", 1372 | "print(f\"Recall (Weighted): {recall}\")\n", 1373 | "print(f\"F1 Score (Weighted): {f1}\")" 1374 | ], 1375 | "metadata": { 1376 | "colab": { 1377 | "base_uri": "https://localhost:8080/" 1378 | }, 1379 | "id": "Z_o4oiqhs9U2", 1380 | "outputId": "04de6bce-55e3-4f32-a9a6-d7cee49bf82e" 1381 | }, 1382 | "execution_count": 312, 1383 | "outputs": [ 1384 | { 1385 | "output_type": "stream", 1386 | "name": "stdout", 1387 | "text": [ 1388 | "Accuracy: 0.829\n", 1389 | "Precision (Weighted): 0.829\n", 1390 | "Recall (Weighted): 1.0\n", 1391 | "F1 Score (Weighted): 0.9065062875888463\n" 1392 | ] 1393 | } 1394 | ] 1395 | }, 1396 | { 1397 | "cell_type": "markdown", 1398 | "source": [ 1399 | "## Salvar o modelo" 1400 | ], 1401 | "metadata": { 1402 | "id": "qlwbno7R4wai" 1403 | } 1404 | }, 1405 | { 1406 | "cell_type": "code", 1407 | "source": [ 1408 | "import pickle\n", 1409 | "import gzip\n", 1410 | "\n", 1411 | "with gzip.open('model.pkl.gz', 'wb') as f:\n", 1412 | " pickle.dump(model, f)" 1413 | ], 1414 | "metadata": { 1415 | "id": "i943GgDguLLJ" 1416 | }, 1417 | "execution_count": 259, 1418 | "outputs": [] 1419 | }, 1420 | { 1421 | "cell_type": "code", 1422 | "source": [ 1423 | "df.to_csv('Dados_tratados.csv', index = False)" 1424 | ], 1425 | "metadata": { 1426 | "id": "CDcub6fA_Xyy" 1427 | }, 1428 | "execution_count": 316, 1429 | "outputs": [] 1430 | }, 1431 | { 1432 | "cell_type": "markdown", 1433 | "source": [], 1434 | "metadata": { 1435 | "id": "iHNX10dNhxOt" 1436 | } 1437 | } 1438 | ] 1439 | } --------------------------------------------------------------------------------