{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":81933,"databundleVersionId":9643020,"sourceType":"competition"}],"dockerImageVersionId":30804,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-05T13:25:18.445819Z","iopub.execute_input":"2024-12-05T13:25:18.446156Z","iopub.status.idle":"2024-12-05T13:25:19.191904Z","shell.execute_reply.started":"2024-12-05T13:25:18.446121Z","shell.execute_reply":"2024-12-05T13:25:19.190780Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"file_path = '/kaggle/input/child-mind-institute-problematic-internet-use/sample_submission.csv'\ndata_sample_submission = pd.read_csv(file_path)\n\n# Menampilkan beberapa baris pertama dari data\nprint(\"Data Sample Submission:\")\nprint(data_sample_submission.head())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-05T13:25:19.193534Z","iopub.execute_input":"2024-12-05T13:25:19.193978Z","iopub.status.idle":"2024-12-05T13:25:19.203918Z","shell.execute_reply.started":"2024-12-05T13:25:19.193930Z","shell.execute_reply":"2024-12-05T13:25:19.202893Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"file_path = '/kaggle/input/child-mind-institute-problematic-internet-use/test.csv'\ndata_test = pd.read_csv(file_path)\n\n# Menampilkan beberapa baris pertama dari data uji\nprint(\"Data Test:\")\nprint(data_test.head())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-05T13:25:19.205130Z","iopub.execute_input":"2024-12-05T13:25:19.205440Z","iopub.status.idle":"2024-12-05T13:25:19.228162Z","shell.execute_reply.started":"2024-12-05T13:25:19.205410Z","shell.execute_reply":"2024-12-05T13:25:19.227193Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"file_path = '/kaggle/input/child-mind-institute-problematic-internet-use/train.csv'\ndata_train = pd.read_csv(file_path)\n\n# Menampilkan beberapa baris pertama dari data pelatihan\nprint(\"Data Train:\")\nprint(data_train.head())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-05T13:25:19.229539Z","iopub.execute_input":"2024-12-05T13:25:19.229948Z","iopub.status.idle":"2024-12-05T13:25:19.283819Z","shell.execute_reply.started":"2024-12-05T13:25:19.229904Z","shell.execute_reply":"2024-12-05T13:25:19.282774Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"file_path = '/kaggle/input/child-mind-institute-problematic-internet-use/data_dictionary.csv'\ndata_dictionary = pd.read_csv(file_path)\n\n# Menampilkan beberapa baris pertama dari data dictionary\nprint(\"Data Dictionary:\")\nprint(data_dictionary.head())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-05T13:25:19.286468Z","iopub.execute_input":"2024-12-05T13:25:19.287305Z","iopub.status.idle":"2024-12-05T13:25:19.296674Z","shell.execute_reply.started":"2024-12-05T13:25:19.287263Z","shell.execute_reply":"2024-12-05T13:25:19.295695Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import cohen_kappa_score\nfrom sklearn.preprocessing import StandardScaler\n\n# Load Dataset\ntrain = pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/train.csv')\ntest = pd.read_csv('/kaggle/input/child-mind-institute-problematic-internet-use/test.csv')\n\n# Feature and Target Selection\nfeatures = ['Physical-BMI', 'Physical-Height', 'Physical-Weight']\ntarget = 'sii'\n\n# Handle Missing Values and Normalize Features\ntrain[features] = train[features].fillna(train[features].median())\ntest[features] = test[features].fillna(test[features].median())\ntrain[target] = train[target].fillna(0).astype(int)\n\nscaler = StandardScaler()\nX = scaler.fit_transform(train[features])\ny = train[target]\n\n# Split Dataset\nX_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=42)\n\n# Simple Perceptron Implementation\nclass SimplePerceptron:\n    def __init__(self, learning_rate=0.01, epochs=100, threshold=0):\n        self.lr = learning_rate\n        self.epochs = epochs\n        self.threshold = threshold\n\n    def fit(self, X, y):\n        n_features = X.shape[1]\n        self.weights = np.zeros(n_features)\n        self.bias = 0\n\n        for _ in range(self.epochs):\n            for x_i, y_i in zip(X, y):\n                prediction = self.predict(x_i)\n                update = self.lr * (y_i - prediction)\n                self.weights += update * x_i\n                self.bias += update\n\n    def predict(self, X):\n        linear_output = np.dot(X, self.weights) + self.bias\n        return (linear_output > self.threshold).astype(int)\n\n# Train Perceptron\nperceptron = SimplePerceptron(learning_rate=0.01, epochs=150, threshold=0.4)\nperceptron.fit(X_train, y_train)\n\n# Evaluate Model\ny_pred = perceptron.predict(X_val)\nkappa_score = cohen_kappa_score(y_val, y_pred, weights='quadratic')\nprint(f\"Kappa Score (Quadratic Weighted): {kappa_score:.4f}\")\nprint(f\"Accuracy: {np.mean(y_pred == y_val) * 100:.2f}%\")\n\n# Predict on Test Data\nX_test = scaler.transform(test[features])\ntest['sii'] = perceptron.predict(X_test)\n\n# Save Submission\nsubmission_file = 'my_perceptron_submission.csv'\ntest[['id', 'sii']].to_csv(submission_file, index=False)\nprint(f\"Submission file saved: {submission_file}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-05T13:25:19.298393Z","iopub.execute_input":"2024-12-05T13:25:19.298809Z","iopub.status.idle":"2024-12-05T13:25:22.738134Z","shell.execute_reply.started":"2024-12-05T13:25:19.298765Z","shell.execute_reply":"2024-12-05T13:25:22.737090Z"}},"outputs":[],"execution_count":null}]}