{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Predictions with the trained RF-models\n", "\n", "Linn Alexandra Emhjellen, 2021.\n" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import os\n", "import matplotlib.pyplot as plt\n", "import joblib\n" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "from sklearn.preprocessing import StandardScaler\n", "from sklearn import datasets, linear_model\n", "from sklearn.ensemble import RandomForestClassifier,RandomForestRegressor\n", "from sklearn.metrics import recall_score,roc_curve,auc\n", "from sklearn.model_selection import cross_val_score\n", "from sklearn.model_selection import cross_val_predict\n", "from sklearn import metrics" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "# vestland dataset\n", "#df_database = pd.read_excel(\"ML_Vestland_database2.xlsx\")\n", "#df_database = pd.read_excel('ML_Lærdal_Aurland_database.xlsx')\n", "#df_database = pd.read_excel('ML_test_area_database.xlsx')\n", "\n", "#df_database = pd.read_csv(\"ML_Vestland_West_10_m_database.csv\")\n", "\n", "#df_database = pd.read_csv('ML_bohme_20m.csv')\n", "\n", "df_database = pd.read_csv('ML_Lærdal_Aurland_close_10_m_database.csv')\n", "df_database = df_database.dropna()\n" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "#df_database MLP" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\LEm\\Anaconda3\\lib\\site-packages\\sklearn\\base.py:310: UserWarning: Trying to unpickle estimator LabelBinarizer from version 0.23.1 when using version 0.24.1. This might lead to breaking code or invalid results. Use at your own risk.\n", " warnings.warn(\n", "C:\\Users\\LEm\\Anaconda3\\lib\\site-packages\\sklearn\\base.py:310: UserWarning: Trying to unpickle estimator MLPClassifier from version 0.23.1 when using version 0.24.1. This might lead to breaking code or invalid results. Use at your own risk.\n", " warnings.warn(\n" ] } ], "source": [ "# load models\n", "\n", "RF_p1_model = joblib.load(\"../MLP/MLP_p1_Emhjellen2.joblib\")\n", "RF_p2_model = joblib.load(\"../MLP/MLP_p2_Emhjellen2.joblib\")\n", "RF_p3_model = joblib.load(\"../MLP/MLP_p3_Emhjellen2.joblib\")\n", "RF_p4_model = joblib.load(\"../MLP/MLP_p4_Emhjellen2.joblib\")\n", "RF_p5_model = joblib.load(\"../MLP/MLP_p5_Emhjellen2.joblib\")\n", "RF_p6_model = joblib.load(\"../MLP/MLP_p6_Emhjellen2.joblib\")\n", "RF_p7_model = joblib.load(\"../MLP/MLP_p7_Emhjellen2.joblib\")\n", "RF_p8_model = joblib.load(\"../MLP/MLP_p8_Emhjellen2.joblib\")" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "#missing_bedrocks = ['Arkose', 'Greenstone', 'Metagreywacke', 'Tonalite', 'Peridotite', 'Meta-arkose', 'Dioritic gneis', 'Pyroclastic rock', 'Quartz diorite', 'Sedimentary breccia', 'Andesite', 'Pyroksenite', 'Charnockite', 'Shale', 'Mica schist', 'Intermediate volcanic rock', 'Trondhjemite', 'Amphibole schist', 'Serpentinite', 'Mangerite', 'Felsic volcanic rock', 'Greywacke', 'Pegmatite/aplite', 'Tuffite', 'Mafic dyke (Diabase, Dolerite)', 'Eclogite', 'Mafic volcanic rock', 'Calcareous mica schist', 'Diorite', 'Garnet mica schist', 'Limestone', 'Basalt', 'Graphitic schist', 'Norite', 'Konglomerate', 'Sandstone', 'Volcanic breccia', 'Quartz dioritic gneiss', 'Dacite', 'Calcite marble', 'Calc-silicate rock', 'Syenite', 'Greenschist', 'Siltstone']\n", "\n", "#missing_bedrocks = ['Intermediate volcanic rock', 'Orthopyroxene gneiss', 'Metagabbro', 'Mangerite', 'Peridotite', 'Banded gneiss', 'Metagreywacke', 'Greywacke', 'Amphibolite', 'Syenite', 'Cataclasite', 'Limestone', 'Monzonitic gneiss', 'Rhyolite', 'Felsic volcanic rock', 'Andesite', 'Phyllite', 'Basalt', 'Mafic volcanic rock', 'Volcanic breccia', 'Tuffite', 'Amphibole schist', 'Mica gneiss', 'Shale', 'Meta-arkose', 'Quartz dioritic gneiss', 'Augengneiss', 'Diorite', 'Eclogite', 'Metasandstone', 'Tonalite', 'Mica schist', 'Serpentinite', 'Greenschist', 'Calcareous phyllite', 'Konglomerate', 'Siltstone', 'Quartz diorite', 'Calcareous mica schist', 'Dioritic gneis', 'Norite', 'Mafic dyke (Diabase, Dolerite)', 'Amphibole gneiss', 'Quartz schist', 'Granodioritic gneiss', 'Sedimentary breccia', 'Dacite', 'Sandstone', 'Pyroksenite', 'Garnet mica schist', 'Pyroclastic rock', 'Anorthosite', 'Pegmatite/aplite', 'Quartzite', 'Mylonite/Phyllonite', 'Calcite marble', 'Granodiorite', 'Graphitic schist', 'Calc-silicate rock', 'Gabbro', 'Arkose', 'Greenstone', 'Migmatite', 'Trondhjemite']\n", "\n", "#missing_bedrocks = ['Granodiorite', 'Dioritic gneis', 'Gabbro', 'Monzodiorite', 'Quartz diorite', 'Tuffite', 'Norite', 'Felsic volcanic rock', 'Basalt', 'Shale', 'Andesite', 'Greenschist', 'Syenite', 'Calcareous phyllite', 'Meta-arkose', 'Arkose', 'Amphibole gneiss', 'Granite', 'Graphitic schist', 'Mafic dyke (Diabase, Dolerite)', 'Amphibole schist', 'Peridotite', 'Monzonitic gneiss', 'Garnet mica schist', 'Greenstone', 'Trondhjemite', 'Charnockite', 'Rhyolite', 'Siltstone', 'Metasandstone', 'Calcareous mica schist', 'Pegmatite/aplite', 'Volcanic breccia', 'Metagabbro', 'Granodioritic gneiss', 'Metagreywacke', 'Pyroclastic rock', 'Mica gneiss', 'Diorite', 'Calc-silicate rock', 'Augengneiss', 'Quartzite', 'Calcite marble', 'Mafic volcanic rock', 'Cataclasite', 'Migmatite', 'Pyroksenite', 'Intermediate volcanic rock', 'Tonalite', 'Mangerite', 'Greywacke', 'Sedimentary breccia', 'Anorthosite', 'Eclogite', 'Monzonite', 'Mylonite/Phyllonite', 'Serpentinite', 'Phyllite', 'Quartz dioritic gneiss', 'Orthopyroxene gneiss', 'Limestone']\n", "\n", "\n", "#missing_bedrocks = ['Intermediate volcanic rock', 'Tonalite', 'Quartz diorite', 'Andesite', 'Tuffite', 'Peridotite', 'Granite', 'Monzonitic gneiss', 'Syenite', 'Metasandstone', 'Mafic volcanic rock', 'Amphibolite', 'Shale', 'Calcite marble', 'Metagabbro', 'Greywacke', 'Cataclasite', 'Amphibole schist', 'Diorite', 'Amphibole gneiss', 'Granodiorite', 'Greenschist', 'Norite', 'Trondhjemite', 'Eclogite', 'Meta-arkose', 'Metagreywacke', 'Charnockite', 'Dioritic gneis', 'Granitic gneiss', 'Dacite', 'Volcanic breccia', 'Calcareous mica schist', 'Mica schist', 'Quartz schist', 'Sedimentary breccia', 'Pegmatite/aplite', 'Granodioritic gneiss', 'Greenstone', 'Garnet mica schist', 'Arkose', 'Calc-silicate rock', 'Pyroksenite', 'Rhyolite', 'Graphitic schist', 'Pyroclastic rock', 'Basalt', 'Monzodiorite', 'Felsic volcanic rock', 'Limestone', 'Mangerite', 'Quartz dioritic gneiss', 'Calcareous phyllite', 'Siltstone', 'Quartzite', 'Konglomerate', 'Banded gneiss', 'Mafic dyke (Diabase, Dolerite)', 'Mylonite/Phyllonite', 'Sandstone', 'Augengneiss', 'Serpentinite']\n", "\n", "#missing_bedrocks = ['Graphitic schist', 'Cataclasite', 'Dioritic gneis', 'Trondhjemite', 'Norite', 'Sedimentary breccia', 'Andesite', 'Mafic dyke (Diabase, Dolerite)', 'Gabbro', 'Quartz diorite', 'Greenstone', 'Dacite', 'Calc-silicate rock', 'Mangerite', 'Metasandstone', 'Quartz schist', 'Phyllite', 'Tonalite', 'Calcareous mica schist', 'Granite', 'Eclogite', 'Pegmatite/aplite', 'Pyroclastic rock', 'Mica gneiss', 'Mafic volcanic rock', 'Konglomerate', 'Intermediate volcanic rock', 'Migmatite', 'Calcareous phyllite', 'Quartzite', 'Diorite', 'Arkose', 'Volcanic breccia', 'Sandstone', 'Garnet mica schist', 'Siltstone', 'Calcite marble', 'Shale', 'Mylonite/Phyllonite', 'Granodioritic gneiss', 'Amphibole gneiss', 'Orthopyroxene gneiss', 'Syenite', 'Rhyolite', 'Banded gneiss', 'Quartz dioritic gneiss', 'Limestone', 'Metagreywacke', 'Basalt', 'Mica schist', 'Metagabbro', 'Granodiorite', 'Felsic volcanic rock', 'Tuffite', 'Meta-arkose', 'Greywacke', 'Peridotite', 'Pyroksenite', 'Augengneiss', 'Serpentinite', 'Greenschist', 'Amphibole schist', 'Amphibolite', 'Monzonitic gneiss']\n", "\n", "missing_bedrocks = ['Graphitic schist', 'Cataclasite', 'Dioritic gneis', 'Trondhjemite', 'Norite', 'Sedimentary breccia', 'Andesite', 'Mafic dyke (Diabase, Dolerite)', 'Gabbro', 'Quartz diorite', 'Greenstone', 'Dacite', 'Calc-silicate rock', 'Mangerite', 'Metasandstone', 'Quartz schist', 'Phyllite', 'Tonalite', 'Calcareous mica schist', 'Granite', 'Eclogite', 'Pegmatite/aplite', 'Pyroclastic rock', 'Mica gneiss', 'Mafic volcanic rock', 'Konglomerate', 'Intermediate volcanic rock', 'Migmatite', 'Calcareous phyllite', 'Quartzite', 'Diorite', 'Arkose', 'Volcanic breccia', 'Sandstone', 'Garnet mica schist', 'Siltstone', 'Calcite marble', 'Shale', 'Mylonite/Phyllonite', 'Granodioritic gneiss', 'Amphibole gneiss', 'Orthopyroxene gneiss', 'Syenite', 'Rhyolite', 'Banded gneiss', 'Quartz dioritic gneiss', 'Limestone', 'Metagreywacke', 'Basalt', 'Mica schist', 'Metagabbro', 'Granodiorite', 'Felsic volcanic rock', 'Tuffite', 'Meta-arkose', 'Greywacke', 'Peridotite', 'Pyroksenite', 'Augengneiss', 'Serpentinite', 'Greenschist', 'Amphibole schist', 'Amphibolite', 'Monzonitic gneiss']" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "# data = nrows*[ncol*[0]]" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "#df = pd.DataFrame(data, columns = ['Arkose', 'Greenstone', 'Metagreywacke', 'Tonalite', 'Peridotite', 'Meta-arkose', 'Dioritic gneis', 'Pyroclastic rock', 'Quartz diorite', 'Sedimentary breccia', 'Andesite', 'Pyroksenite', 'Charnockite', 'Shale', 'Mica schist', 'Intermediate volcanic rock', 'Trondhjemite', 'Amphibole schist', 'Serpentinite', 'Mangerite', 'Felsic volcanic rock', 'Greywacke', 'Pegmatite/aplite', 'Tuffite', 'Mafic dyke (Diabase, Dolerite)', 'Eclogite', 'Mafic volcanic rock', 'Calcareous mica schist', 'Diorite', 'Garnet mica schist', 'Limestone', 'Basalt', 'Graphitic schist', 'Norite', 'Konglomerate', 'Sandstone', 'Volcanic breccia', 'Quartz dioritic gneiss', 'Dacite', 'Calcite marble', 'Calc-silicate rock', 'Syenite', 'Greenschist', 'Siltstone'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " , , , , , , , , 'Konglomerate', 'Sandstone', 'Volcanic breccia', 'Quartz dioritic gneiss', 'Dacite', 'Calcite marble', 'Calc-silicate rock', 'Syenite', 'Greenschist', 'Siltstone'] " ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Graphitic schist\n", "Cataclasite\n", "Dioritic gneis\n", "Trondhjemite\n", "Norite\n", "Sedimentary breccia\n", "Andesite\n", "Mafic dyke (Diabase, Dolerite)\n", "Gabbro\n", "Quartz diorite\n", "Greenstone\n", "Dacite\n", "Calc-silicate rock\n", "Mangerite\n", "Metasandstone\n", "Quartz schist\n", "Phyllite\n", "Tonalite\n", "Calcareous mica schist\n", "Granite\n", "Eclogite\n", "Pegmatite/aplite\n", "Pyroclastic rock\n", "Mica gneiss\n", "Mafic volcanic rock\n", "Konglomerate\n", "Intermediate volcanic rock\n", "Migmatite\n", "Calcareous phyllite\n", "Quartzite\n", "Diorite\n", "Arkose\n", "Volcanic breccia\n", "Sandstone\n", "Garnet mica schist\n", "Siltstone\n", "Calcite marble\n", "Shale\n", "Mylonite/Phyllonite\n", "Granodioritic gneiss\n", "Amphibole gneiss\n", "Orthopyroxene gneiss\n", "Syenite\n", "Rhyolite\n", "Banded gneiss\n", "Quartz dioritic gneiss\n", "Limestone\n", "Metagreywacke\n", "Basalt\n", "Mica schist\n", "Metagabbro\n", "Granodiorite\n", "Felsic volcanic rock\n", "Tuffite\n", "Meta-arkose\n", "Greywacke\n", "Peridotite\n", "Pyroksenite\n", "Augengneiss\n", "Serpentinite\n", "Greenschist\n", "Amphibole schist\n", "Amphibolite\n", "Monzonitic gneiss\n" ] } ], "source": [ "for i in missing_bedrocks:\n", " print(i)\n", " df_database[i] = 0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "df_database['Arkose'] = 0\n", "df_database['Greenstone'] = 0 \n", "df_database['Metagreywacke'] = 0\n", "df_database['Tonalite'] = 0\n", "df_database['Peridotite'] = 0\n", "df_database['Meta-arkose'] = 0\n", "df_database['Dioritic gneis'] = 0\n", "df_database['Pyroclastic rock'] = 0\n", "df_database['Quartz diorite'] = 0\n", "df_database['Sedimentary breccia'] = 0\n", "df_database['Andesite'] = 0\n", "df_database['Pyroksenite'] = 0\n", "df_database['Charnockite'] = 0\n", "df_database['Shale'] = 0\n", "df_database['Mica schist'] = 0\n", "df_database['Intermediate volcanic rock'] = 0\n", "df_database['Trondhjemite'] = 0\n", "df_database['Amphibole schist'] = 0\n", "df_database['Serpentinite'] = 0\n", "df_database['Mangerite'] = 0\n", "df_database['Felsic volcanic rock'] = 0\n", "df_database['Greywacke'] = 0\n", "df_database['Pegmatite/aplite'] = 0\n", "df_database['Tuffite'] = 0\n", "df_database['Mafic dyke (Diabase, Dolerite)'] = 0\n", "df_database['Mafic volcanic rock'] = 0\n", "df_database['Calcareous mica schist'] = 0\n", "df_database['Diorite'] = 0\n", "df_database['Garnet mica schist'] = 0\n", "df_database['Limestone'] = 0\n", "df_database['Basalt'] = 0\n", "df_database['Graphitic schist'] = 0\n", "df_database['Norite'] = 0\n" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Unnamed: 0POINT_XPOINT_YElevationSlopeAspectProfile_curvPlan_curvFlow_dirFlow_acc...Meta-arkoseGreywackePeridotitePyrokseniteAugengneissSerpentiniteGreenschistAmphibole schistAmphiboliteMonzonitic gneiss
00101094.65696.783938e+061467.68627911.878660304.019867-0.262793-1.7836673223.0...0000000000
11101104.65696.783938e+061469.95800819.852732279.5197752.550231-1.061951163.0...0000000000
22101114.65696.783938e+061474.78149424.584663283.4783630.529975-0.117486162.0...0000000000
33101124.65696.783938e+061479.67456115.338610302.604187-4.2683523.376789160.0...0000000000
44101134.65696.783938e+061479.13537612.626880306.5889892.684932-2.928960328.0...0000000000
\n", "

5 rows × 93 columns

\n", "
" ], "text/plain": [ " Unnamed: 0 POINT_X POINT_Y Elevation Slope Aspect \\\n", "0 0 101094.6569 6.783938e+06 1467.686279 11.878660 304.019867 \n", "1 1 101104.6569 6.783938e+06 1469.958008 19.852732 279.519775 \n", "2 2 101114.6569 6.783938e+06 1474.781494 24.584663 283.478363 \n", "3 3 101124.6569 6.783938e+06 1479.674561 15.338610 302.604187 \n", "4 4 101134.6569 6.783938e+06 1479.135376 12.626880 306.588989 \n", "\n", " Profile_curv Plan_curv Flow_dir Flow_acc ... Meta-arkose Greywacke \\\n", "0 -0.262793 -1.783667 32 23.0 ... 0 0 \n", "1 2.550231 -1.061951 16 3.0 ... 0 0 \n", "2 0.529975 -0.117486 16 2.0 ... 0 0 \n", "3 -4.268352 3.376789 16 0.0 ... 0 0 \n", "4 2.684932 -2.928960 32 8.0 ... 0 0 \n", "\n", " Peridotite Pyroksenite Augengneiss Serpentinite Greenschist \\\n", "0 0 0 0 0 0 \n", "1 0 0 0 0 0 \n", "2 0 0 0 0 0 \n", "3 0 0 0 0 0 \n", "4 0 0 0 0 0 \n", "\n", " Amphibole schist Amphibolite Monzonitic gneiss \n", "0 0 0 0 \n", "1 0 0 0 \n", "2 0 0 0 \n", "3 0 0 0 \n", "4 0 0 0 \n", "\n", "[5 rows x 93 columns]" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_database.head()" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [], "source": [ "# feature combinations\n", "p1 = df_database[['Slope']]\n", "\n", "p2 = df_database[['Slope','Elevation']]\n", "\n", "p3 = df_database[['Slope','North','East','North East','North West','South','South East','South West','West']]\n", "\n", "p4 = df_database[['Slope','Elevation','Plan_curv','Profile_curv','TRI','Distance_to_roads']]\n", "\n", "p5 = df_database[['Slope','Elevation','Plan_curv','Profile_curv','TRI','Flow_dir','Flow_acc','Distance_to_roads']]\n", "\n", "p6 = df_database[['Slope','Elevation','Plan_curv','Profile_curv','TRI']]\n", "\n", "p7 = df_database[['Elevation','North','East','North East','North West','South','South East','South West','West','Plan_curv','Profile_curv','TRI','Flow_dir','Flow_acc','Distance_to_roads']]\n", "\n", "p8 = df_database[['Slope','Elevation','North','East','North East','North West','South','South East','South West','West','Plan_curv','Profile_curv','TRI','Flow_dir','Flow_acc','Distance_to_roads',\n", " 'Granite','Granodiorite','Tonalite','Trondhjemite','Syenite','Monzonite','Monzodiorite','Quartz diorite','Diorite','Gabbro','Norite','Peridotite','Pyroksenite','Charnockite','Mangerite','Anorthosite','Mafic dyke (Diabase, Dolerite)','Pegmatite/aplite','Felsic volcanic rock','Rhyolite','Dacite','Intermediate volcanic rock','Andesite','Mafic volcanic rock','Basalt',\n", " 'Pyroclastic rock','Volcanic breccia','Siltstone','Sandstone','Greywacke','Arkose','Konglomerate','Sedimentary breccia','Limestone','Tuffite','Shale','Phyllite','Mica schist','Garnet mica schist','Calcareous phyllite','Calcareous mica schist','Amphibole schist','Graphitic schist','Calcite marble',\n", " 'Metasandstone','Metagreywacke','Meta-arkose','Quartzite','Quartz schist','Mica gneiss','Calc-silicate rock','Amphibole gneiss','Granitic gneiss','Granodioritic gneiss','Tonalitic gneiss','Quartz dioritic gneiss','Monzonitic gneiss','Dioritic gneis','Orthopyroxene gneiss','Migmatite','Augengneiss',\n", " 'Banded gneiss','Greenschist','Greenstone','Amphibolite','Metagabbro','Eclogite','Serpentinite','Mylonite/Phyllonite','Cataclasite']]\n", "\n", "feature_combinations = [p1,p2,p3,p4,p5,p6,p7,p8]" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "x_p1 = p1[~np.isnan(p1).any(axis=1)]\n", "x_p2 = p2[~np.isnan(p2).any(axis=1)]\n", "x_p3 = p3[~np.isnan(p3).any(axis=1)]\n", "x_p4 = p4[~np.isnan(p4).any(axis=1)]\n", "x_p5 = p5[~np.isnan(p5).any(axis=1)]\n", "x_p6 = p6[~np.isnan(p6).any(axis=1)]\n", "x_p7 = p7[~np.isnan(p7).any(axis=1)]\n", "x_p8 = p8[~np.isnan(p8).any(axis=1)]\n", "\n", "x_p = [x_p1,x_p2,x_p3,x_p4,x_p5,x_p6,x_p7,x_p8]" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [], "source": [ "rf_models = [RF_p1_model,RF_p2_model,RF_p3_model,RF_p4_model,RF_p5_model,RF_p6_model,RF_p7_model,RF_p8_model]\n", "\n", "predictions = []\n", "pred_probabilities = []\n", "\n", "for i in range(0,len(x_p)):\n", " \n", " AUTO_SCALING = True\n", " if AUTO_SCALING:\n", " scaler = StandardScaler()\n", " scaler.fit(x_p[i])\n", " x_p_i = scaler.transform(x_p[i])\n", " \n", " p_i_predictions = rf_models[i].predict(x_p_i)\n", " predictions.append(p_i_predictions)\n", " \n", " prob_p_i = rf_models[i].predict_proba(x_p_i)\n", " pred_probabilities.append(prob_p_i)\n", " " ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [], "source": [ "df_coor = df_database[['POINT_X', 'POINT_Y']]" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[9.99525595e-01, 4.74404611e-04],\n", " [9.94714183e-01, 5.28581662e-03],\n", " [9.71288820e-01, 2.87111803e-02],\n", " ...,\n", " [9.97188899e-01, 2.81110055e-03],\n", " [9.98319746e-01, 1.68025368e-03],\n", " [9.98782718e-01, 1.21728231e-03]])" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pred_probabilities[0]" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ ":1: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_coor['RF_Vestland_pred_p1'] = predictions[0]\n", ":2: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_coor['RF_Vestland_prob_p1'] = pred_probabilities[0][:,1]\n" ] } ], "source": [ "df_coor['RF_Vestland_pred_p1'] = predictions[0]\n", "df_coor['RF_Vestland_prob_p1'] = pred_probabilities[0][:,1]" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ ":1: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_coor['RF_Vestland_pred_p2'] = predictions[1]\n", ":2: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_coor['RF_Vestland_prob_p2'] = pred_probabilities[1][:,1]\n" ] } ], "source": [ "df_coor['RF_Vestland_pred_p2'] = predictions[1]\n", "df_coor['RF_Vestland_prob_p2'] = pred_probabilities[1][:,1]" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ ":1: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_coor['RF_Vestland_pred_p3'] = predictions[2]\n", ":2: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_coor['RF_Vestland_prob_p3'] = pred_probabilities[2][:,1]\n" ] } ], "source": [ "df_coor['RF_Vestland_pred_p3'] = predictions[2]\n", "df_coor['RF_Vestland_prob_p3'] = pred_probabilities[2][:,1]" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ ":1: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_coor['RF_Vestland_pred_p4'] = predictions[3]\n", ":2: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_coor['RF_Vestland_prob_p4'] = pred_probabilities[3][:,1]\n" ] } ], "source": [ "df_coor['RF_Vestland_pred_p4'] = predictions[3]\n", "df_coor['RF_Vestland_prob_p4'] = pred_probabilities[3][:,1]" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ ":1: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_coor['RF_Vestland_pred_p5'] = predictions[4]\n", ":2: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_coor['RF_Vestland_prob_p5'] = pred_probabilities[4][:,1]\n" ] } ], "source": [ "df_coor['RF_Vestland_pred_p5'] = predictions[4]\n", "df_coor['RF_Vestland_prob_p5'] = pred_probabilities[4][:,1]" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ ":1: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_coor['RF_Vestland_pred_p6'] = predictions[5]\n", ":2: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_coor['RF_Vestland_prob_p6'] = pred_probabilities[5][:,1]\n" ] } ], "source": [ "df_coor['RF_Vestland_pred_p6'] = predictions[5]\n", "df_coor['RF_Vestland_prob_p6'] = pred_probabilities[5][:,1]" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ ":1: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_coor['RF_Vestland_pred_p7'] = predictions[6]\n", ":2: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_coor['RF_Vestland_prob_p7'] = pred_probabilities[6][:,1]\n" ] } ], "source": [ "df_coor['RF_Vestland_pred_p7'] = predictions[6]\n", "df_coor['RF_Vestland_prob_p7'] = pred_probabilities[6][:,1]" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ ":1: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_coor['RF_Vestland_pred_p8'] = predictions[7]\n", ":2: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " df_coor['RF_Vestland_prob_p8'] = pred_probabilities[7][:,1]\n" ] } ], "source": [ "df_coor['RF_Vestland_pred_p8'] = predictions[7]\n", "df_coor['RF_Vestland_prob_p8'] = pred_probabilities[7][:,1]" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [], "source": [ "#df_coor.to_csv(\"RF_results_Bohme_20m.csv\")\n", "#df_coor.to_csv('MLP_results_Vestland_West_10.csv')\n", "df_coor.to_csv('MLP_results_lærdal_aurland_close_10.csv')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "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.8.3" } }, "nbformat": 4, "nbformat_minor": 4 }