├── iris_model.pkl ├── consumer.py ├── docker-compose.yaml ├── producer.py ├── README.md ├── data_generator.py ├── LICENSE └── pycaret.ipynb /iris_model.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/turkalpmd/-machine-learning-on-streaming-data-using-Kafka-and-Docker/HEAD/iris_model.pkl -------------------------------------------------------------------------------- /consumer.py: -------------------------------------------------------------------------------- 1 | import json 2 | import pandas as pd 3 | from kafka import KafkaConsumer 4 | from pycaret.classification import load_model 5 | from pycaret.classification import* 6 | 7 | # path name must be same with producer. 8 | model = load_model('/home/izzet/Desktop/projects/basic_project/iris_model.pkl') 9 | 10 | if __name__ == '__main__': 11 | # Kafka Consumer 12 | consumer = KafkaConsumer( 13 | 'iris_pycaret', # topic name !!!! 14 | # that the consumer should contact to bootstrap initial cluster metadata. 15 | bootstrap_servers='localhost:9092', 16 | # A name for this client. 17 | client_id = 'kafka-python-{version}', # Default 18 | # The name of the consumer group to join for dynamic partition assignment (if enabled), 19 | # and to use for fetching and committing offsets. 20 | group_id = None, # 21 | # key_deserializer 22 | # value_deserializer 23 | auto_offset_reset='earliest' 24 | # for other knowledges; 25 | # https://kafka-python.readthedocs.io/en/master/apidoc/KafkaConsumer.html 26 | 27 | ) 28 | 29 | for message in consumer: 30 | # firstly load to consumer data then transfer to pandas dataframe 31 | prediction_data = pd.read_json(json.loads(message.value)) 32 | #print(prediction_data) 33 | print(predict_model(model,prediction_data)) 34 | 35 | 36 | -------------------------------------------------------------------------------- /docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | zookeeper: 4 | image: confluentinc/cp-zookeeper:7.0.1 5 | networks: 6 | - kaf-cluster 7 | environment: 8 | ZOOKEEPER_CLIENT_PORT: 2181 9 | ports: 10 | - 2181:2181 11 | kafka: 12 | image: confluentinc/cp-kafka:7.0.1 13 | networks: 14 | - kaf-cluster 15 | depends_on: 16 | - zookeeper 17 | environment: 18 | KAFKA_BROKER_ID: 1 19 | KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 20 | KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:19092,PLAINTEXT_HOST://localhost:9092 21 | KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT 22 | KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 23 | ports: 24 | - 9092:9092 25 | kafdrop: 26 | image: obsidiandynamics/kafdrop:3.29.0 27 | networks: 28 | - kaf-cluster 29 | depends_on: 30 | - kafka 31 | ports: 32 | - 9000:9000 33 | environment: 34 | KAFKA_BROKERCONNECT: kafka:19092 35 | networks: 36 | kaf-cluster: 37 | driver: bridge 38 | 39 | # kaynak: https://github.com/cigdemkadakoglu/apache-kafka 40 | 41 | # # Stop services only 42 | # docker-compose stop 43 | 44 | # # Stop and remove containers, networks.. 45 | # docker-compose down 46 | 47 | # # Down and remove volumes 48 | # docker-compose down --volumes 49 | 50 | # # Down and remove images 51 | # docker-compose down --rmi -------------------------------------------------------------------------------- /producer.py: -------------------------------------------------------------------------------- 1 | import time 2 | import json 3 | import random 4 | from datetime import datetime 5 | from data_generator import iris_data_creator 6 | from kafka import KafkaProducer 7 | 8 | # Messages will be serialized as JSON 9 | def serializer(message): 10 | return json.dumps(message).encode('utf-8') 11 | 12 | # Kafka Producer 13 | producer = KafkaProducer( 14 | # producer should contact to bootstrap initial cluster metadata 15 | bootstrap_servers=['localhost:9092'], 16 | # client_id (str) – a name for this client. 17 | client_id = "kafka-python-producer-#", #this id is default 18 | # used to convert user-supplied message values to bytes. 19 | # key_serializer (callable) – used to convert user-supplied keys to bytes 20 | # value_serializer (callable) – used to convert user-supplied message values to bytes. 21 | value_serializer=serializer, 22 | # The number of acknowledgments the producer requires the leader to have received before considering a request complete. 23 | # 0: Producer will not wait for any acknowledgment from the server. 24 | # 1: Wait for leader to write the record to its local log only. 25 | # all: Wait for the full set of in-sync replicas to write the record. 26 | acks = "all", 27 | # for more knowledge: https://kafka-python.readthedocs.io/en/master/apidoc/KafkaProducer.htm 28 | ) 29 | 30 | if __name__ == '__main__': 31 | # Infinite loop - runs until you kill the program 32 | while True: 33 | # Generate a message 34 | dummy_message = iris_data_creator() 35 | 36 | # Send it to our 'messages' topic 37 | print(f'Producing message @ {datetime.now()} | Message = {str(dummy_message)}') 38 | producer.send('iris_pycaret', dummy_message) 39 | 40 | # Sleep for a random number of seconds 41 | time_to_sleep = random.randint(1, 2) 42 | time.sleep(time_to_sleep) 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # -machine-learning-on-streaming-data-using-Kafka-and-Docker 2 | I have completed my first project that machine learning on streaming data using Kafka and Docker. You can check-up my GitHub repository for codes. 3 | 4 | 5 | # Steps of process: 6 | ##### 1- install vscode 7 | ##### 2- install anaconda 8 | ##### 3- create nev enviroment on conda 9 | ##### 4- install docker 10 | ##### 5- install docker-compose 11 | ##### 6- install docker desktop (https://www.youtube.com/watch?v=Vplj9b0L_1Y) 12 | ##### 7- download docker-compose.yaml (https://github.com/cigdemkadakoglu/apache-kafka) 13 | ##### 8- docker-composeup -d 14 | * https://www.youtube.com/playlist?list=PLZYKO7600KN9ttvG0mFYzP82AbIdeJYwq this video very useful but Turkish. (sonunda bu espriyi yapabildim.) 15 | ##### 9- you can check containers with docker ps or docker stats -a 16 | ##### 10- create topic 17 | * I am really hardned with creating topic. Because of sh bash or another concepts are far to my domain. 18 | * But, our container named kafdrop also have create topic function. 19 | * You can write on the browser bar: https://localhost:9000/ 20 | ![Screenshot from 2022-07-31 00-03-18](https://user-images.githubusercontent.com/85236337/181996082-3a1e92fe-f819-4b06-8061-4e79b4085e4a.png) 21 | * create a new topic it is easier way for create topics. 22 | 23 | ##### 11- I love pycaret library 24 | * setup() 25 | * create_model() 26 | * tune_model() 27 | * save_model() 28 | * Here is complex at API docs, you have to save the model with path_name just like pandas save function. 29 | * load_model() 30 | * And also when loading model, you must take path_name. 31 | * How it easy, yeah? 32 | 33 | ##### 11 - I created random data generator named as data_generator.py 34 | * I used iris dataset, you can change this. 35 | ##### 12 - I used this module for producer.py 36 | * same topic, proper ports 37 | ##### 13 - Then, I used consumer.py 38 | * same topic, proper ports 39 | * load_model 40 | * print result 41 | ##### 42 | # Coming soon.... 43 | ## Send data to MongoDB 44 | -------------------------------------------------------------------------------- /data_generator.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | import numpy as np 3 | import scipy.stats 4 | from sklearn.datasets import load_iris 5 | 6 | iris = load_iris() 7 | df = pd.DataFrame(iris['data'], columns = iris['feature_names']) 8 | df['target'] = pd.Series(iris['target'], name = 'target_values') 9 | df['target_name'] = df['target'].replace([0,1,2], 10 | ['iris-' + species for species in iris['target_names'].tolist()]) 11 | 12 | 13 | 14 | def my_distribution(min_val, max_val, mean, std): 15 | scale = max_val - min_val 16 | location = min_val 17 | # Mean and standard deviation of the unscaled beta distribution 18 | unscaled_mean = (mean - min_val) / scale 19 | unscaled_var = (std / scale) ** 2 20 | # Computation of alpha and beta can be derived from mean and variance formulas 21 | t = unscaled_mean / (1 - unscaled_mean) 22 | beta = ((t / unscaled_var) - (t * t) - (2 * t) - 1) / ((t * t * t) + (3 * t * t) + (3 * t) + 1) 23 | alpha = beta * t 24 | # Not all parameters may produce a valid distribution 25 | if alpha <= 0 or beta <= 0: 26 | raise ValueError('Cannot create distribution for the given parameters.') 27 | # Make scaled beta distribution with computed parameters 28 | return scipy.stats.beta(alpha, beta, scale=scale, loc=location) 29 | 30 | np.random.seed(100) 31 | 32 | 33 | def iris_data_creator(iteration=1): 34 | sl_list = [] 35 | sw_list = [] 36 | pl_list = [] 37 | pw_list = [] 38 | 39 | for i in range(iteration): 40 | 41 | min_val_sl = df["sepal length (cm)"].min() 42 | max_val_sl = df["sepal length (cm)"].max() 43 | mean_sl = df["sepal length (cm)"].mean(skipna=True) 44 | std_sl = df["sepal length (cm)"].std(skipna=True) 45 | my_dist_sl = my_distribution(min_val_sl, max_val_sl, mean_sl, std_sl) 46 | sample_sl = my_dist_sl.rvs(size=1).round(1)[0] 47 | sl_list.append(sample_sl) 48 | 49 | for i in range(iteration): 50 | 51 | min_val_sw = df['sepal width (cm)'].min() 52 | max_val_sw = df['sepal width (cm)'].max() 53 | mean_sw = df['sepal width (cm)'].mean(skipna=True) 54 | std_sw = df['sepal width (cm)'].std(skipna=True) 55 | my_dist_sw = my_distribution(min_val_sw, max_val_sw, mean_sw, std_sw) 56 | sample_sw = my_dist_sw.rvs(size=1).round(1)[0] 57 | sw_list.append(sample_sw) 58 | 59 | for i in range(iteration): 60 | 61 | min_val_pl = df["petal length (cm)"].min() 62 | max_val_pl = df["petal length (cm)"].max() 63 | mean_pl = df["petal length (cm)"].mean(skipna=True) 64 | std_pl = df["petal length (cm)"].std(skipna=True) 65 | my_dist_pl = my_distribution(min_val_pl, max_val_pl, mean_pl, std_pl) 66 | sample_pl = my_dist_pl.rvs(size=1).round(1)[0] 67 | pl_list.append(sample_pl) 68 | 69 | for i in range(iteration): 70 | 71 | min_val_pw = df["petal width (cm)"].min() 72 | max_val_pw = df["petal width (cm)"].max() 73 | mean_pw = df["petal width (cm)"].mean(skipna=True) 74 | std_pw = df["petal width (cm)"].std(skipna=True) 75 | my_dist_pw = my_distribution(min_val_pw, max_val_pw, mean_pw, std_pw) 76 | sample_pw = my_dist_pw.rvs(size=1).round(1)[0] 77 | pw_list.append(sample_pw) 78 | 79 | random_df = pd.DataFrame() 80 | random_df['sepal_length'] = sl_list 81 | random_df['sepal_width'] = sw_list 82 | random_df['petal_length'] = pl_list 83 | random_df['petal_width'] = pw_list 84 | 85 | 86 | return random_df.to_json() 87 | 88 | # for i in range(1): 89 | # if __name__ == '__main__': 90 | # print(iris_data_creator(iteration=1)) 91 | 92 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /pycaret.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "data": { 10 | "text/html": [ 11 | "
\n", 12 | "\n", 25 | "\n", 26 | " \n", 27 | " \n", 28 | " \n", 29 | " \n", 30 | " \n", 31 | " \n", 32 | " \n", 33 | " \n", 34 | " \n", 35 | " \n", 36 | " \n", 37 | " \n", 38 | " \n", 39 | " \n", 40 | " \n", 41 | " \n", 42 | " \n", 43 | " \n", 44 | " \n", 45 | " \n", 46 | " \n", 47 | " \n", 48 | " \n", 49 | " \n", 50 | " \n", 51 | " \n", 52 | " \n", 53 | " \n", 54 | " \n", 55 | " \n", 56 | " \n", 57 | " \n", 58 | " \n", 59 | " \n", 60 | " \n", 61 | " \n", 62 | " \n", 63 | " \n", 64 | " \n", 65 | " \n", 66 | " \n", 67 | " \n", 68 | " \n", 69 | " \n", 70 | " \n", 71 | " \n", 72 | " \n", 73 | " \n", 74 | " \n", 75 | " \n", 76 | " \n", 77 | " \n", 78 | "
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
05.13.51.40.2Iris-setosa
14.93.01.40.2Iris-setosa
24.73.21.30.2Iris-setosa
34.63.11.50.2Iris-setosa
45.03.61.40.2Iris-setosa
\n", 79 | "
" 80 | ], 81 | "text/plain": [ 82 | " sepal_length sepal_width petal_length petal_width species\n", 83 | "0 5.1 3.5 1.4 0.2 Iris-setosa\n", 84 | "1 4.9 3.0 1.4 0.2 Iris-setosa\n", 85 | "2 4.7 3.2 1.3 0.2 Iris-setosa\n", 86 | "3 4.6 3.1 1.5 0.2 Iris-setosa\n", 87 | "4 5.0 3.6 1.4 0.2 Iris-setosa" 88 | ] 89 | }, 90 | "metadata": {}, 91 | "output_type": "display_data" 92 | } 93 | ], 94 | "source": [ 95 | "from pycaret.datasets import get_data\n", 96 | "data = get_data('iris')\n", 97 | "from pycaret.classification import*" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": 2, 103 | "metadata": {}, 104 | "outputs": [ 105 | { 106 | "data": { 107 | "text/plain": [ 108 | "Index(['sepal_length', 'sepal_width', 'petal_length', 'petal_width',\n", 109 | " 'species'],\n", 110 | " dtype='object')" 111 | ] 112 | }, 113 | "execution_count": 2, 114 | "metadata": {}, 115 | "output_type": "execute_result" 116 | } 117 | ], 118 | "source": [ 119 | "data.columns" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": 3, 125 | "metadata": {}, 126 | "outputs": [ 127 | { 128 | "data": { 129 | "text/html": [ 130 | "\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 | " \n", 265 | " \n", 266 | " \n", 267 | " \n", 268 | " \n", 269 | " \n", 270 | " \n", 271 | " \n", 272 | " \n", 273 | " \n", 274 | " \n", 275 | " \n", 276 | " \n", 277 | " \n", 278 | " \n", 279 | " \n", 280 | " \n", 281 | " \n", 282 | " \n", 283 | " \n", 284 | " \n", 285 | " \n", 286 | " \n", 287 | " \n", 288 | " \n", 289 | " \n", 290 | " \n", 291 | " \n", 292 | " \n", 293 | " \n", 294 | " \n", 295 | " \n", 296 | " \n", 297 | " \n", 298 | " \n", 299 | " \n", 300 | " \n", 301 | " \n", 302 | " \n", 303 | " \n", 304 | " \n", 305 | " \n", 306 | " \n", 307 | " \n", 308 | " \n", 309 | " \n", 310 | " \n", 311 | " \n", 312 | " \n", 313 | " \n", 314 | " \n", 315 | " \n", 316 | " \n", 317 | " \n", 318 | " \n", 319 | " \n", 320 | " \n", 321 | " \n", 322 | " \n", 323 | " \n", 324 | " \n", 325 | " \n", 326 | " \n", 327 | " \n", 328 | " \n", 329 | " \n", 330 | " \n", 331 | " \n", 332 | " \n", 333 | " \n", 334 | " \n", 335 | " \n", 336 | " \n", 337 | " \n", 338 | " \n", 339 | " \n", 340 | " \n", 341 | " \n", 342 | " \n", 343 | " \n", 344 | " \n", 345 | " \n", 346 | " \n", 347 | " \n", 348 | " \n", 349 | " \n", 350 | " \n", 351 | " \n", 352 | " \n", 353 | " \n", 354 | " \n", 355 | " \n", 356 | " \n", 357 | " \n", 358 | " \n", 359 | " \n", 360 | " \n", 361 | " \n", 362 | " \n", 363 | " \n", 364 | " \n", 365 | " \n", 366 | " \n", 367 | " \n", 368 | " \n", 369 | " \n", 370 | " \n", 371 | " \n", 372 | " \n", 373 | " \n", 374 | " \n", 375 | " \n", 376 | " \n", 377 | " \n", 378 | " \n", 379 | " \n", 380 | " \n", 381 | " \n", 382 | " \n", 383 | " \n", 384 | " \n", 385 | " \n", 386 | " \n", 387 | " \n", 388 | " \n", 389 | " \n", 390 | " \n", 391 | " \n", 392 | " \n", 393 | " \n", 394 | " \n", 395 | " \n", 396 | " \n", 397 | " \n", 398 | " \n", 399 | " \n", 400 | " \n", 401 | " \n", 402 | " \n", 403 | " \n", 404 | " \n", 405 | " \n", 406 | " \n", 407 | " \n", 408 | " \n", 409 | " \n", 410 | " \n", 411 | " \n", 412 | " \n", 413 | " \n", 414 | " \n", 415 | " \n", 416 | " \n", 417 | " \n", 418 | " \n", 419 | " \n", 420 | " \n", 421 | " \n", 422 | " \n", 423 | " \n", 424 | " \n", 425 | " \n", 426 | " \n", 427 | " \n", 428 | " \n", 429 | " \n", 430 | " \n", 431 | " \n", 432 | " \n", 433 | " \n", 434 | " \n", 435 | " \n", 436 | " \n", 437 | " \n", 438 | " \n", 439 | " \n", 440 | " \n", 441 | " \n", 442 | " \n", 443 | " \n", 444 | " \n", 445 | "
 DescriptionValue
0session_id42
1Targetspecies
2Target TypeMulticlass
3Label EncodedIris-setosa: 0, Iris-versicolor: 1, Iris-virginica: 2
4Original Data(150, 5)
5Missing ValuesFalse
6Numeric Features4
7Categorical Features0
8Ordinal FeaturesFalse
9High Cardinality FeaturesFalse
10High Cardinality MethodNone
11Transformed Train Set(114, 3)
12Transformed Test Set(30, 3)
13Shuffle Train-TestTrue
14Stratify Train-TestFalse
15Fold GeneratorStratifiedKFold
16Fold Number10
17CPU Jobs-1
18Use GPUFalse
19Log ExperimentFalse
20Experiment Nameclf-default-name
21USIb820
22Imputation Typeiterative
23Iterative Imputation Iteration5
24Numeric Imputermean
25Iterative Imputation Numeric ModelLight Gradient Boosting Machine
26Categorical Imputerconstant
27Iterative Imputation Categorical ModelLight Gradient Boosting Machine
28Unknown Categoricals Handlingleast_frequent
29NormalizeTrue
30Normalize Methodrobust
31TransformationFalse
32Transformation MethodNone
33PCAFalse
34PCA MethodNone
35PCA ComponentsNone
36Ignore Low VarianceFalse
37Combine Rare LevelsFalse
38Rare Level ThresholdNone
39Numeric BinningFalse
40Remove OutliersTrue
41Outliers Threshold0.050000
42Remove MulticollinearityTrue
43Multicollinearity Threshold0.900000
44Remove Perfect CollinearityTrue
45ClusteringFalse
46Clustering IterationNone
47Polynomial FeaturesFalse
48Polynomial DegreeNone
49Trignometry FeaturesFalse
50Polynomial ThresholdNone
51Group FeaturesFalse
52Feature SelectionFalse
53Feature Selection Methodclassic
54Features Selection ThresholdNone
55Feature InteractionFalse
56Feature RatioFalse
57Interaction ThresholdNone
58Fix ImbalanceFalse
59Fix Imbalance MethodSMOTE
\n" 446 | ], 447 | "text/plain": [ 448 | "" 449 | ] 450 | }, 451 | "metadata": {}, 452 | "output_type": "display_data" 453 | } 454 | ], 455 | "source": [ 456 | "s = setup(data,\n", 457 | "target='species',\n", 458 | "numeric_features = ['sepal_length', 'sepal_width',\n", 459 | " 'petal_length', 'petal_width'],\n", 460 | "session_id=42,\n", 461 | "train_size = 0.8, \n", 462 | "data_split_shuffle=True,\n", 463 | "remove_multicollinearity=True,\n", 464 | "remove_outliers=True,\n", 465 | "normalize=True,\n", 466 | "normalize_method=\"robust\",\n", 467 | "use_gpu=False,\n", 468 | "fold_shuffle=True,\n", 469 | "imputation_type='iterative')" 470 | ] 471 | }, 472 | { 473 | "cell_type": "code", 474 | "execution_count": 4, 475 | "metadata": {}, 476 | "outputs": [ 477 | { 478 | "data": { 479 | "text/html": [ 480 | "\n", 501 | "\n", 502 | " \n", 503 | " \n", 504 | " \n", 505 | " \n", 506 | " \n", 507 | " \n", 508 | " \n", 509 | " \n", 510 | " \n", 511 | " \n", 512 | " \n", 513 | " \n", 514 | " \n", 515 | " \n", 516 | " \n", 517 | " \n", 518 | " \n", 519 | " \n", 520 | " \n", 521 | " \n", 522 | " \n", 523 | " \n", 524 | " \n", 525 | " \n", 526 | " \n", 527 | " \n", 528 | " \n", 529 | " \n", 530 | " \n", 531 | " \n", 532 | " \n", 533 | " \n", 534 | " \n", 535 | " \n", 536 | " \n", 537 | " \n", 538 | " \n", 539 | " \n", 540 | " \n", 541 | " \n", 542 | " \n", 543 | " \n", 544 | " \n", 545 | " \n", 546 | " \n", 547 | " \n", 548 | " \n", 549 | " \n", 550 | " \n", 551 | " \n", 552 | " \n", 553 | " \n", 554 | " \n", 555 | " \n", 556 | " \n", 557 | " \n", 558 | " \n", 559 | " \n", 560 | " \n", 561 | " \n", 562 | " \n", 563 | " \n", 564 | " \n", 565 | " \n", 566 | " \n", 567 | " \n", 568 | " \n", 569 | " \n", 570 | " \n", 571 | " \n", 572 | " \n", 573 | " \n", 574 | " \n", 575 | " \n", 576 | " \n", 577 | " \n", 578 | " \n", 579 | " \n", 580 | " \n", 581 | " \n", 582 | " \n", 583 | " \n", 584 | " \n", 585 | " \n", 586 | " \n", 587 | " \n", 588 | " \n", 589 | " \n", 590 | " \n", 591 | " \n", 592 | " \n", 593 | " \n", 594 | " \n", 595 | " \n", 596 | " \n", 597 | " \n", 598 | " \n", 599 | " \n", 600 | " \n", 601 | " \n", 602 | " \n", 603 | " \n", 604 | " \n", 605 | " \n", 606 | " \n", 607 | " \n", 608 | " \n", 609 | " \n", 610 | " \n", 611 | " \n", 612 | " \n", 613 | " \n", 614 | " \n", 615 | " \n", 616 | " \n", 617 | " \n", 618 | " \n", 619 | " \n", 620 | " \n", 621 | " \n", 622 | " \n", 623 | " \n", 624 | " \n", 625 | " \n", 626 | " \n", 627 | " \n", 628 | " \n", 629 | " \n", 630 | " \n", 631 | " \n", 632 | " \n", 633 | " \n", 634 | " \n", 635 | " \n", 636 | " \n", 637 | " \n", 638 | " \n", 639 | " \n", 640 | " \n", 641 | " \n", 642 | " \n", 643 | " \n", 644 | " \n", 645 | " \n", 646 | " \n", 647 | " \n", 648 | " \n", 649 | " \n", 650 | " \n", 651 | " \n", 652 | " \n", 653 | " \n", 654 | " \n", 655 | " \n", 656 | " \n", 657 | " \n", 658 | " \n", 659 | " \n", 660 | " \n", 661 | " \n", 662 | " \n", 663 | " \n", 664 | " \n", 665 | " \n", 666 | " \n", 667 | " \n", 668 | " \n", 669 | " \n", 670 | " \n", 671 | " \n", 672 | " \n", 673 | " \n", 674 | " \n", 675 | " \n", 676 | " \n", 677 | " \n", 678 | " \n", 679 | " \n", 680 | " \n", 681 | " \n", 682 | " \n", 683 | " \n", 684 | " \n", 685 | " \n", 686 | " \n", 687 | " \n", 688 | " \n", 689 | " \n", 690 | " \n", 691 | " \n", 692 | " \n", 693 | " \n", 694 | " \n", 695 | " \n", 696 | " \n", 697 | " \n", 698 | " \n", 699 | " \n", 700 | " \n", 701 | " \n", 702 | " \n", 703 | " \n", 704 | " \n", 705 | " \n", 706 | " \n", 707 | " \n", 708 | " \n", 709 | " \n", 710 | "
 ModelAccuracyAUCRecallPrec.F1KappaMCCTT (Sec)
ldaLinear Discriminant Analysis0.94620.99480.94890.95380.94570.91860.92280.0120
qdaQuadratic Discriminant Analysis0.93710.99480.94060.94530.93620.90480.90980.0120
lrLogistic Regression0.92880.97510.93330.93720.92720.89270.89780.5410
lightgbmLight Gradient Boosting Machine0.92800.97240.93220.93440.92720.89110.89500.0410
nbNaive Bayes0.91970.97300.92500.93310.91740.87940.88730.0110
gbcGradient Boosting Classifier0.91210.95050.91560.92510.91050.86730.87470.1350
etExtra Trees Classifier0.91140.98280.91560.92330.90940.86610.87330.1180
xgboostExtreme Gradient Boosting0.91140.95440.91560.92330.90940.86610.87330.2040
catboostCatBoost Classifier0.91140.96960.91560.92330.90940.86610.87330.5460
rfRandom Forest Classifier0.90230.97270.90720.91650.90030.85250.86080.1500
knnK Neighbors Classifier0.89390.96810.90170.91980.88820.84030.85600.0180
dtDecision Tree Classifier0.88640.91340.89060.89330.88510.82860.83310.0120
svmSVM - Linear Kernel0.86670.00000.87560.90040.85850.79940.82010.0140
adaAda Boost Classifier0.80680.94200.80440.81730.78560.70730.73800.0720
ridgeRidge Classifier0.80610.00000.81110.81780.80180.70820.71760.0110
dummyDummy Classifier0.36060.50000.33330.13120.19200.00000.00000.0110
\n" 711 | ], 712 | "text/plain": [ 713 | "" 714 | ] 715 | }, 716 | "metadata": {}, 717 | "output_type": "display_data" 718 | } 719 | ], 720 | "source": [ 721 | "best_model = compare_models()" 722 | ] 723 | }, 724 | { 725 | "cell_type": "code", 726 | "execution_count": 5, 727 | "metadata": {}, 728 | "outputs": [ 729 | { 730 | "data": { 731 | "text/html": [ 732 | "\n", 737 | "\n", 738 | " \n", 739 | " \n", 740 | " \n", 741 | " \n", 742 | " \n", 743 | " \n", 744 | " \n", 745 | " \n", 746 | " \n", 747 | " \n", 748 | " \n", 749 | " \n", 750 | " \n", 751 | " \n", 752 | " \n", 753 | " \n", 754 | " \n", 755 | " \n", 756 | " \n", 757 | " \n", 758 | " \n", 759 | " \n", 760 | " \n", 761 | " \n", 762 | " \n", 763 | " \n", 764 | " \n", 765 | " \n", 766 | " \n", 767 | " \n", 768 | " \n", 769 | " \n", 770 | " \n", 771 | " \n", 772 | " \n", 773 | " \n", 774 | " \n", 775 | " \n", 776 | " \n", 777 | " \n", 778 | " \n", 779 | " \n", 780 | " \n", 781 | " \n", 782 | " \n", 783 | " \n", 784 | " \n", 785 | " \n", 786 | " \n", 787 | " \n", 788 | " \n", 789 | " \n", 790 | " \n", 791 | " \n", 792 | " \n", 793 | " \n", 794 | " \n", 795 | " \n", 796 | " \n", 797 | " \n", 798 | " \n", 799 | " \n", 800 | " \n", 801 | " \n", 802 | " \n", 803 | " \n", 804 | " \n", 805 | " \n", 806 | " \n", 807 | " \n", 808 | " \n", 809 | " \n", 810 | " \n", 811 | " \n", 812 | " \n", 813 | " \n", 814 | " \n", 815 | " \n", 816 | " \n", 817 | " \n", 818 | " \n", 819 | " \n", 820 | " \n", 821 | " \n", 822 | " \n", 823 | " \n", 824 | " \n", 825 | " \n", 826 | " \n", 827 | " \n", 828 | " \n", 829 | " \n", 830 | " \n", 831 | " \n", 832 | " \n", 833 | " \n", 834 | " \n", 835 | " \n", 836 | " \n", 837 | " \n", 838 | " \n", 839 | " \n", 840 | " \n", 841 | " \n", 842 | " \n", 843 | " \n", 844 | " \n", 845 | " \n", 846 | " \n", 847 | " \n", 848 | " \n", 849 | " \n", 850 | " \n", 851 | " \n", 852 | " \n", 853 | " \n", 854 | " \n", 855 | " \n", 856 | " \n", 857 | " \n", 858 | " \n", 859 | " \n", 860 | " \n", 861 | " \n", 862 | " \n", 863 | " \n", 864 | " \n", 865 | " \n", 866 | " \n", 867 | " \n", 868 | " \n", 869 | " \n", 870 | " \n", 871 | " \n", 872 | " \n", 873 | " \n", 874 | " \n", 875 | " \n", 876 | " \n", 877 | " \n", 878 | " \n", 879 | " \n", 880 | " \n", 881 | " \n", 882 | "
 AccuracyAUCRecallPrec.F1KappaMCC
Fold       
01.00001.00001.00001.00001.00001.00001.0000
10.91671.00000.91670.93330.91530.87500.8843
21.00001.00001.00001.00001.00001.00001.0000
31.00001.00001.00001.00001.00001.00001.0000
41.00001.00001.00001.00001.00001.00001.0000
50.90911.00000.88890.92730.90510.86080.8721
61.00001.00001.00001.00001.00001.00001.0000
70.90911.00000.93330.93180.91050.86250.8735
80.81820.94810.83330.81820.81820.72500.7250
90.90911.00000.91670.92730.90760.86250.8735
Mean0.94620.99480.94890.95380.94570.91860.9228
Std0.05990.01560.05690.05600.06020.09060.0882
\n" 883 | ], 884 | "text/plain": [ 885 | "" 886 | ] 887 | }, 888 | "metadata": {}, 889 | "output_type": "display_data" 890 | } 891 | ], 892 | "source": [ 893 | "lda = create_model(\"lda\")" 894 | ] 895 | }, 896 | { 897 | "cell_type": "code", 898 | "execution_count": 6, 899 | "metadata": {}, 900 | "outputs": [ 901 | { 902 | "data": { 903 | "text/html": [ 904 | "\n", 909 | "\n", 910 | " \n", 911 | " \n", 912 | " \n", 913 | " \n", 914 | " \n", 915 | " \n", 916 | " \n", 917 | " \n", 918 | " \n", 919 | " \n", 920 | " \n", 921 | " \n", 922 | " \n", 923 | " \n", 924 | " \n", 925 | " \n", 926 | " \n", 927 | " \n", 928 | " \n", 929 | " \n", 930 | " \n", 931 | " \n", 932 | " \n", 933 | " \n", 934 | " \n", 935 | " \n", 936 | " \n", 937 | " \n", 938 | " \n", 939 | " \n", 940 | " \n", 941 | " \n", 942 | " \n", 943 | " \n", 944 | " \n", 945 | " \n", 946 | " \n", 947 | " \n", 948 | " \n", 949 | " \n", 950 | " \n", 951 | " \n", 952 | " \n", 953 | " \n", 954 | " \n", 955 | " \n", 956 | " \n", 957 | " \n", 958 | " \n", 959 | " \n", 960 | " \n", 961 | " \n", 962 | " \n", 963 | " \n", 964 | " \n", 965 | " \n", 966 | " \n", 967 | " \n", 968 | " \n", 969 | " \n", 970 | " \n", 971 | " \n", 972 | " \n", 973 | " \n", 974 | " \n", 975 | " \n", 976 | " \n", 977 | " \n", 978 | " \n", 979 | " \n", 980 | " \n", 981 | " \n", 982 | " \n", 983 | " \n", 984 | " \n", 985 | " \n", 986 | " \n", 987 | " \n", 988 | " \n", 989 | " \n", 990 | " \n", 991 | " \n", 992 | " \n", 993 | " \n", 994 | " \n", 995 | " \n", 996 | " \n", 997 | " \n", 998 | " \n", 999 | " \n", 1000 | " \n", 1001 | " \n", 1002 | " \n", 1003 | " \n", 1004 | " \n", 1005 | " \n", 1006 | " \n", 1007 | " \n", 1008 | " \n", 1009 | " \n", 1010 | " \n", 1011 | " \n", 1012 | " \n", 1013 | " \n", 1014 | " \n", 1015 | " \n", 1016 | " \n", 1017 | " \n", 1018 | " \n", 1019 | " \n", 1020 | " \n", 1021 | " \n", 1022 | " \n", 1023 | " \n", 1024 | " \n", 1025 | " \n", 1026 | " \n", 1027 | " \n", 1028 | " \n", 1029 | " \n", 1030 | " \n", 1031 | " \n", 1032 | " \n", 1033 | " \n", 1034 | " \n", 1035 | " \n", 1036 | " \n", 1037 | " \n", 1038 | " \n", 1039 | " \n", 1040 | " \n", 1041 | " \n", 1042 | " \n", 1043 | " \n", 1044 | " \n", 1045 | " \n", 1046 | " \n", 1047 | " \n", 1048 | " \n", 1049 | " \n", 1050 | " \n", 1051 | " \n", 1052 | " \n", 1053 | " \n", 1054 | "
 AccuracyAUCRecallPrec.F1KappaMCC
Fold       
01.00001.00001.00001.00001.00001.00001.0000
10.91671.00000.91670.93330.91530.87500.8843
21.00001.00001.00001.00001.00001.00001.0000
31.00001.00001.00001.00001.00001.00001.0000
41.00001.00001.00001.00001.00001.00001.0000
50.90911.00000.88890.92730.90510.86080.8721
61.00001.00001.00001.00001.00001.00001.0000
70.90911.00000.93330.93180.91050.86250.8735
80.81820.94810.83330.81820.81820.72500.7250
90.90911.00000.91670.92730.90760.86250.8735
Mean0.94620.99480.94890.95380.94570.91860.9228
Std0.05990.01560.05690.05600.06020.09060.0882
\n" 1055 | ], 1056 | "text/plain": [ 1057 | "" 1058 | ] 1059 | }, 1060 | "metadata": {}, 1061 | "output_type": "display_data" 1062 | } 1063 | ], 1064 | "source": [ 1065 | "tuned_model = tune_model(lda,fold=10,optimize=\"Accuracy\",\n", 1066 | "search_library=\"tune-sklearn\",\n", 1067 | " search_algorithm=\"bayesian\",\n", 1068 | " choose_better=False,\n", 1069 | " n_iter=5)" 1070 | ] 1071 | }, 1072 | { 1073 | "cell_type": "code", 1074 | "execution_count": 7, 1075 | "metadata": {}, 1076 | "outputs": [ 1077 | { 1078 | "data": { 1079 | "application/vnd.jupyter.widget-view+json": { 1080 | "model_id": "6d2378ecc6704ba1a3e22407d27839d6", 1081 | "version_major": 2, 1082 | "version_minor": 0 1083 | }, 1084 | "text/plain": [ 1085 | "interactive(children=(ToggleButtons(description='Plot Type:', icons=('',), options=(('Hyperparameters', 'param…" 1086 | ] 1087 | }, 1088 | "metadata": {}, 1089 | "output_type": "display_data" 1090 | } 1091 | ], 1092 | "source": [ 1093 | "evaluate_model(best_model)" 1094 | ] 1095 | }, 1096 | { 1097 | "cell_type": "code", 1098 | "execution_count": 8, 1099 | "metadata": {}, 1100 | "outputs": [ 1101 | { 1102 | "name": "stdout", 1103 | "output_type": "stream", 1104 | "text": [ 1105 | "Transformation Pipeline and Model Successfully Saved\n" 1106 | ] 1107 | }, 1108 | { 1109 | "data": { 1110 | "text/plain": [ 1111 | "(Pipeline(memory=None,\n", 1112 | " steps=[('dtypes',\n", 1113 | " DataTypes_Auto_infer(categorical_features=[],\n", 1114 | " display_types=True, features_todrop=[],\n", 1115 | " id_columns=[],\n", 1116 | " ml_usecase='classification',\n", 1117 | " numerical_features=['sepal_length',\n", 1118 | " 'sepal_width',\n", 1119 | " 'petal_length',\n", 1120 | " 'petal_width'],\n", 1121 | " target='species', time_features=[])),\n", 1122 | " ('imputer',\n", 1123 | " Iterative_Imputer(add_indicator=False,\n", 1124 | " classifier=LGBMClassifi...\n", 1125 | " ('fix_multi',\n", 1126 | " Fix_multicollinearity(correlation_with_target_preference=None,\n", 1127 | " correlation_with_target_threshold=0.0,\n", 1128 | " target_variable='species',\n", 1129 | " threshold=0.9)),\n", 1130 | " ('dfs', 'passthrough'), ('pca', 'passthrough'),\n", 1131 | " ['trained_model',\n", 1132 | " LinearDiscriminantAnalysis(n_components=None, priors=None,\n", 1133 | " shrinkage=None, solver='svd',\n", 1134 | " store_covariance=False,\n", 1135 | " tol=0.0001)]],\n", 1136 | " verbose=False),\n", 1137 | " '/home/izzet/Desktop/projects/basic_project/iris_model.pkl.pkl')" 1138 | ] 1139 | }, 1140 | "execution_count": 8, 1141 | "metadata": {}, 1142 | "output_type": "execute_result" 1143 | } 1144 | ], 1145 | "source": [ 1146 | "save_model(lda,\"/home/izzet/Desktop/projects/basic_project/iris_model.pkl\")" 1147 | ] 1148 | }, 1149 | { 1150 | "cell_type": "code", 1151 | "execution_count": null, 1152 | "metadata": {}, 1153 | "outputs": [], 1154 | "source": [] 1155 | } 1156 | ], 1157 | "metadata": { 1158 | "kernelspec": { 1159 | "display_name": "Python 3.9.13 ('datascience')", 1160 | "language": "python", 1161 | "name": "python3" 1162 | }, 1163 | "language_info": { 1164 | "codemirror_mode": { 1165 | "name": "ipython", 1166 | "version": 3 1167 | }, 1168 | "file_extension": ".py", 1169 | "mimetype": "text/x-python", 1170 | "name": "python", 1171 | "nbconvert_exporter": "python", 1172 | "pygments_lexer": "ipython3", 1173 | "version": "3.9.13" 1174 | }, 1175 | "orig_nbformat": 4, 1176 | "vscode": { 1177 | "interpreter": { 1178 | "hash": "d5e3d835a3425d0426acedd99e77a951ca3551842067eb24f0bf8de3598cac8b" 1179 | } 1180 | } 1181 | }, 1182 | "nbformat": 4, 1183 | "nbformat_minor": 2 1184 | } 1185 | --------------------------------------------------------------------------------