{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"PS-Simple-model-in-river.ipynb","provenance":[{"file_id":"1u8EYbBuXlR5SZZwILAGZF-3z_gVRea0d","timestamp":1652123613133}],"collapsed_sections":[],"authorship_tag":"ABX9TyMeNEuqYj5srMKN10jXOLhI"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":1,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"XfP114XqKM8M","executionInfo":{"status":"ok","timestamp":1652201292603,"user_tz":-60,"elapsed":5908,"user":{"displayName":"Claudia Soares","userId":"01695063174396797696"}},"outputId":"35765fb2-be14-4c83-8c98-c7d976b56f9b"},"outputs":[{"output_type":"stream","name":"stdout","text":["Collecting river\n"," Downloading river-0.10.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB)\n","\u001b[K |████████████████████████████████| 2.0 MB 7.3 MB/s \n","\u001b[?25hRequirement already satisfied: numpy>=1.20.0 in /usr/local/lib/python3.7/dist-packages (from river) (1.21.6)\n","Requirement already satisfied: scipy>=1.4.1 in /usr/local/lib/python3.7/dist-packages (from river) (1.4.1)\n","Requirement already satisfied: pandas>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from river) (1.3.5)\n","Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/dist-packages (from pandas>=1.0.1->river) (2022.1)\n","Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas>=1.0.1->river) (2.8.2)\n","Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.7.3->pandas>=1.0.1->river) (1.15.0)\n","Installing collected packages: river\n","Successfully installed river-0.10.1\n"]}],"source":["!pip install river"]},{"cell_type":"code","source":["from river import datasets\n","from river import evaluate\n","from river import linear_model\n","from river import metrics\n","from river import optim\n","from river import preprocessing\n","\n","dataset = datasets.Phishing()\n","\n","model = (preprocessing.StandardScaler() | linear_model.LogisticRegression(optimizer=optim.SGD(.1)))\n","\n","metric = metrics.Accuracy()\n","\n","evaluate.progressive_val_score(dataset, model, metric)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"Xl5kje8UKWNl","executionInfo":{"status":"ok","timestamp":1652201337646,"user_tz":-60,"elapsed":3797,"user":{"displayName":"Claudia Soares","userId":"01695063174396797696"}},"outputId":"3f6ef682-4ea9-4d6e-9135-285df5e727a3"},"execution_count":3,"outputs":[{"output_type":"execute_result","data":{"text/plain":["Accuracy: 88.96%"]},"metadata":{},"execution_count":3}]},{"cell_type":"code","source":["model"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":800},"id":"AxnI-JDqKdWu","executionInfo":{"status":"ok","timestamp":1652201339026,"user_tz":-60,"elapsed":264,"user":{"displayName":"Claudia Soares","userId":"01695063174396797696"}},"outputId":"6f4366a2-ca36-412b-e07a-e53577a5ee93"},"execution_count":4,"outputs":[{"output_type":"execute_result","data":{"text/plain":["Pipeline (\n"," StandardScaler (\n"," with_std=True\n"," ),\n"," LogisticRegression (\n"," optimizer=SGD (\n"," lr=Constant (\n"," learning_rate=0.1\n"," )\n"," )\n"," loss=Log (\n"," weight_pos=1.\n"," weight_neg=1.\n"," )\n"," l2=0.\n"," intercept_init=0.\n"," intercept_lr=Constant (\n"," learning_rate=0.01\n"," )\n"," clip_gradient=1e+12\n"," initializer=Zeros ()\n"," )\n",")"],"text/html":["
StandardScaler
\n","{'counts': Counter({'empty_server_form_handler': 1250,\n"," 'popup_window': 1250,\n"," 'https': 1250,\n"," 'request_from_other_domain': 1250,\n"," 'anchor_from_other_domain': 1250,\n"," 'is_popular': 1250,\n"," 'long_url': 1250,\n"," 'age_of_domain': 1250,\n"," 'ip_in_url': 1250}),\n"," 'means': defaultdict(<class 'float'>,\n"," {'age_of_domain': 0.6000000000000005,\n"," 'anchor_from_other_domain': 0.49880000000000085,\n"," 'empty_server_form_handler': 0.6300000000000001,\n"," 'https': 0.6563999999999994,\n"," 'ip_in_url': 0.11359999999999992,\n"," 'is_popular': 0.5071999999999998,\n"," 'long_url': 0.45679999999999976,\n"," 'popup_window': 0.3732000000000003,\n"," 'request_from_other_domain': 0.41280000000000017}),\n"," 'vars': defaultdict(<class 'float'>,\n"," {'age_of_domain': 0.23999999999999996,\n"," 'anchor_from_other_domain': 0.22019855999999993,\n"," 'empty_server_form_handler': 0.20770000000000016,\n"," 'https': 0.1729390399999999,\n"," 'ip_in_url': 0.10069503999999997,\n"," 'is_popular': 0.15954816,\n"," 'long_url': 0.14053376000000012,\n"," 'popup_window': 0.11412176000000009,\n"," 'request_from_other_domain': 0.16199615999999983}),\n"," 'with_std': True}\n","\n","
LogisticRegression
\n","{'_weights': {'empty_server_form_handler': -1.8020681139138652, 'popup_window': -1.9129723543042834, 'https': -1.242054777443942, 'request_from_other_domain': -0.5514160814020197, 'anchor_from_other_domain': 0.2467407702650704, 'is_popular': 0.176126810771945, 'long_url': -0.4089115951955724, 'age_of_domain': -0.18306008536055804, 'ip_in_url': 0.17536770195408036},\n"," '_y_name': None,\n"," 'clip_gradient': 1000000000000.0,\n"," 'initializer': Zeros (),\n"," 'intercept': -0.40049775224094364,\n"," 'intercept_init': 0.0,\n"," 'intercept_lr': Constant({'learning_rate': 0.01}),\n"," 'l2': 0.0,\n"," 'loss': Log({'weight_pos': 1.0, 'weight_neg': 1.0}),\n"," 'optimizer': SGD({'lr': Constant({'learning_rate': 0.1}), 'n_iterations': 1250})}\n","\n","