<commit_before><commit_msg>ML Assignment 3 submission<commit_after>{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "csv = np.genfromtxt('train_data.csv', delimiter = \",\")\n",
    "size_data = len(csv[1:,:])\n",
    "var0 = np.ones(size_data).reshape(1, size_data)\n",
    "var = np.concatenate((var0, np.transpose(csv[1:, 0:4])))\n",
    "target = csv[1:, 4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "theta = np.zeros(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def dif_cost(n):\n",
    "    dJ = 0\n",
    "    alpha = 0.5\n",
    "    h = np.dot(theta, var)\n",
    "    dJ = np.sum(np.dot((h - target), var[n, :]))\n",
    "    dJ = alpha * dJ / size_data  \n",
    "    return dJ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "new_th = np.zeros(5)    \n",
    "n_iter = 1000\n",
    "for i in range(0, n_iter):\n",
    "    for j in range(0, 5):\n",
    "        new_th[j] = theta[j] - dif_cost(j)   \n",
    "    theta = new_th"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 1.66824986  0.71837337  3.12743084  0.42506237  1.2152172 ]\n"
     ]
    }
   ],
   "source": [
    "print(theta) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "csv2 = np.genfromtxt('test_input.csv', delimiter = \",\")\n",
    "size_inp = len(csv2[1:,:])\n",
    "inp_var0 = np.ones(size_inp).reshape(1, size_inp)\n",
    "inp_var = np.concatenate((inp_var0, np.transpose(csv2[1:, 0:4])))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "out_h = np.dot(theta, inp_var)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 175,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "np.savetxt(\"test_output2.csv\", out_h, delimiter=\",\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}

{'fraction_non_alphanumeric': 0.2289826627412496, 'fraction_numerical': 0.035982989859339225, 'mean_word_length': 2.4398200224971878, 'pattern_counts': {'":': 75, '<': 3, '<?xml version=': 0, '>': 3, '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}}
{'dir': 'git-commits-cleaned', 'id': '5930970', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1282, 'n_words': 212}