<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jainam Mehta on Medium]]></title>
        <description><![CDATA[Stories by Jainam Mehta on Medium]]></description>
        <link>https://medium.com/@jainamm47?source=rss-48cc54d4d0e5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*ANcIM2RNVobbdJejYmZspg.jpeg</url>
            <title>Stories by Jainam Mehta on Medium</title>
            <link>https://medium.com/@jainamm47?source=rss-48cc54d4d0e5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 10:32:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jainamm47/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Combining Data Cleaning, Feature Selection, Modeling and Interpretability]]></title>
            <link>https://medium.com/@jainamm47/combining-data-cleaning-feature-selection-modeling-and-interpretability-837b51e6d870?source=rss-48cc54d4d0e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/837b51e6d870</guid>
            <category><![CDATA[automl]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[regression]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Jainam Mehta]]></dc:creator>
            <pubDate>Wed, 26 Apr 2023 22:56:08 GMT</pubDate>
            <atom:updated>2023-04-26T23:01:03.509Z</atom:updated>
            <content:encoded><![CDATA[<h3>Idea</h3><p>Combining data cleaning, feature selection, modeling, and interpretability is a crucial and iterative process in data analysis and machine learning. Data cleaning involves handling missing values, outliers, and inconsistencies to ensure the quality and reliability of the dataset. Feature selection helps identify the most relevant variables that contribute significantly to the predictive model’s performance, reducing dimensionality and enhancing computational efficiency. The modeling phase involves selecting an appropriate algorithm or model to train and evaluate using the cleaned dataset and selected features. Finally, interpretability techniques provide insights into understanding the model’s decision-making process, allowing for better trust, transparency, and potential improvements. By integrating these steps, data practitioners can enhance the accuracy, efficiency, and interpretability of their models, enabling them to make informed and reliable decisions based on the analyzed data.</p><h3>DataSet</h3><p>We will use the dataset called <strong>Lower Back Pain Symptoms </strong>from Kaggle.</p><p><a href="https://www.kaggle.com/datasets/sammy123/lower-back-pain-symptoms-dataset">Lower Back Pain Symptoms Dataset</a></p><h3>About DataSet</h3><p>310 Observations, 13 Attributes (12 Numeric Predictors, 1 Binary Class Attribute — No Demographics)</p><p>Numerous issues with any section of the intricate, interrelated network of spinal muscles, nerves, bones, discs, or tendons in the lumbar spine can result in lower back discomfort. The following are typical causes of low back pain:</p><p>* The large nerve roots in the low back that go to the legs may be irritated</p><p>* The smaller nerves that supply the low back may be irritated</p><p>* The large paired lower back muscles (erector spinae) may be strained</p><p>* The bones, ligaments or joints may be damaged</p><p>* An intervertebral disc may be degenerating</p><p>Lower back pain, as well as pain that radiates or is referred to other parts of the body, can be brought on by an irritation or issue with any of these tissues. Back muscle spasms, which may not seem like much but can cause excruciating pain and incapacity, are a common side effect of lower back disorders.</p><p>Although lower back pain is very prevalent, there is a wide range in its symptoms and intensity. Simple lower back muscle strains may be so painful as to require a trip to the ER, whereas a degenerating disc may only cause minor, sporadic discomfort.</p><p>Using information about the physical spine that has been gathered, this data set will determine whether a person is abnormal or normal.</p><p>This data set is about to identify a person is abnormal or normal using collected physical spine details/data.</p><p>The data set consists of :</p><p>1. Twelve numerical features leading to Spine problem</p><p>2. Class attribute indicates if the person has a spine problem or not</p><p>3. There are a total of 311 observations.</p><h3>Approach</h3><p>We will use some common libraries for creating Machine Learning models and than running analysis on it. Libraries that we will initially use are</p><ul><li>nump: It is a popular library for numerical computing in Python.</li><li>pandas: It provides data structures and functions for data manipulation and analysis.</li><li>matplotlib.pyplot: It is a plotting library for creating visualizations in Python.</li><li>seaborn: It is a data visualization library based on matplotlib, providing a high-level interface for creating attractive and informative statistical graphics.</li><li>sklearn.preprocessing: It provides various classes for data preprocessing, including scaling, encoding, and imputation.</li><li>sklearn.svm: It includes the implementation of Support Vector Machines (SVM), a popular machine learning algorithm used for classification and regression tasks.</li><li>sklearn.naive_bayes: It provides implementations of the Naive Bayes algorithm, a probabilistic classifier based on Bayes&#39; theorem.</li><li>sklearn.linear_model: It includes the implementation of various linear models, such as logistic regression.</li><li>xgboost: It is an optimized gradient boosting library that provides efficient implementations of gradient boosting algorithms.</li><li>sklearn.model_selection: It includes functions for splitting datasets into train and test sets for model evaluation and selection.</li></ul><p>The notebook attached below has the code that runs through how do we do Feature Selection and Data Cleaning in the given dataset. I have written the code for analyzing the data given to get a better view of how the data looks and how it is processing</p><p><a href="https://colab.research.google.com/drive/1JDj7d4IY2u8Rk_0Rql0GQN0dTedtNWM1?usp=sharing">Google Colaboratory</a></p><h3>Explanation</h3><p>In this notebook we initially start with analyzing the data like checking for null values than getting description of the dataset to understand which column from the set weighs more important to determine if the user has a Abnormal or normal back. For getting a better understanding we use help of correlation matrix to understand pattern and use qqplot which compares the quantiles of the dataset against the quantiles of the theoretical distribution, typically a standard normal distribution.</p><p>Moving on we get the VIF (Variance Inflation Factor) values of all the columns. A VIF of 1 indicates that there is no multicollinearity between the predictor variable and the other predictor variables in the model. A VIF greater than 1 indicates that the predictor variable is correlated with one or more other predictor variables in the model. The VIF values we get are</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*ilnp5-b_VHL7Nhs-B7VynA.png" /></figure><p>This proves there is a high collinearity.</p><p>After plotting a few graphs to visualize the data we move on to detect outliers which refer to observations or data points that significantly deviate from the typical patterns or values in a dataset. These are data points that are unusually distant from the majority of the other data points, and they can have a significant impact on statistical analysis, modeling, and machine learning algorithms. We observe that these columns have outliers</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*JwUgpOYoWqn0MTnhxvoeIQ.png" /></figure><p>So we remove them to clean the data to fit it in the machine learning algorithm. Before trying to fit our data into a Machine Learning Algorithm we do a bit feature selection to understand which ones are important it basically calculates and displays the feature importances for a classifier based on the X_train data</p><p>After that we start with the cool part which is to start writing the machine learning algorithms. We use DecisionTreeClassifier and GridSearchCV algorithm to predict the unknown values and check if it makes correct predictions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*V9kTO1hZi7E3Ywj4aYsz1A.png" /></figure><p>The MSE and RMSE of both are near 0 which is good but we can make it better by doing Regularization and doing some tuning in the model to make it more accurate for the unknown data. We will try another algorithm like KNN to check if it predicts more accurate</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MDI9o74ZQyChlDlCXFbGuw.png" /></figure><p>We can see that it performs better than GridSearch and DecisionTreeClassifier.</p><h3>Modeling</h3><p>Now focusing on creating better models after cleaning the data we will use a library called AutoML from H2O which will run our data across multiple algorithms and find the best one that suits for our needs and making accurate results. The notebook given below has all the code on how will we use the library and getting the best model</p><p><a href="https://colab.research.google.com/drive/1rOAWw41BaqfOX33A6aVWCFI2ZdCpNjb1?usp=sharing">Google Colaboratory</a></p><h4>AutoML</h4><p>AutoML, or Automated Machine Learning, refers to the process of automating various tasks involved in machine learning, including data preprocessing, feature engineering, model selection, hyperparameter tuning, and model evaluation. The goal of AutoML is to simplify and streamline the machine learning workflow, making it more accessible to users with limited expertise in data science and machine learning.</p><p>AutoML tools and platforms leverage advanced algorithms and techniques to automate the different stages of the machine learning pipeline. These tools often provide a user-friendly interface that allows users to define their problem, upload their data, and initiate the automated process. AutoML systems typically explore different algorithms and model architectures, optimize hyperparameters, and even perform ensemble learning to generate the best-performing model for a given dataset.</p><p>AutoML offers several advantages. It reduces the time and effort required to develop machine learning models, making it possible for non-experts to apply machine learning techniques to their problems. It also helps in reducing human bias by automating the feature engineering and model selection process. AutoML enables faster experimentation and iteration, allowing users to explore a wider range of models and hyperparameters in a shorter time frame.</p><p>Some popular AutoML platforms and libraries include Google Cloud AutoML, H2O.ai, AutoKeras, and TPOT. These tools often support various machine learning tasks, such as classification, regression, time series forecasting, and natural language processing. They also provide features for model interpretation and explainability, allowing users to gain insights into the model’s decision-making process.</p><p>However, it is important to note that while AutoML can greatly simplify the machine learning workflow, it does not eliminate the need for human expertise entirely. Users still need to have a good understanding of the underlying concepts and be able to interpret and validate the results produced by AutoML systems. Additionally, AutoML may not always outperform manual approaches, especially in cases where domain knowledge and expert insights play a crucial role.</p><p>Overall, AutoML has emerged as a valuable tool in democratizing machine learning, enabling users with varying levels of expertise to leverage the power of AI and make data-driven decisions. Its continued development and adoption are expected to drive further advancements in the field of machine learning and empower a wider range of users to harness the potential of AI.</p><p>After fitting our data and trying multiple algorithms we get the result like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LeJ-BWnShs0y6ULyDx1aIA.png" /></figure><p>We see that the best Model is Stacked Ensemble giving the best results</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b8jfeAFrJ6WbG3oby5m3Cg.png" /></figure><p>The MSE and RMSE value both are near 0 from which we can observe that it can make accurate predictions on the unknown dataset</p><h4>Confusion Matrix</h4><p>A confusion matrix is a table that is commonly used to evaluate the performance of a classification model. It provides a comprehensive summary of the predicted and actual class labels of a dataset. The matrix is particularly useful when dealing with problems that involve multiple classes or categories.</p><p>The confusion matrix consists of four main components: true positives (TP), true negatives (TN), false positives (FP), and false negatives (FN). These components represent the counts or frequencies of correctly and incorrectly classified instances. The matrix is organized into rows and columns, where each row corresponds to the instances in a predicted class and each column corresponds to the instances in an actual class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lgE4_rJTduI_25sgxojJSQ.png" /><figcaption>Confusion Matrix by AutoML</figcaption></figure><h3>SHAP Analysis</h3><p>SHAP (SHapley Additive exPlanations) analysis is a technique used in the field of machine learning and explainable artificial intelligence (XAI) to understand the contribution of individual features or variables in a model’s prediction. It provides a way to assign a numerical value to each feature, indicating its importance or impact on the model’s output.</p><p>The core idea behind SHAP analysis is derived from cooperative game theory and the concept of Shapley values. It aims to provide a fair allocation of the prediction’s outcome among the input features by considering all possible combinations of features and their contributions. In this way, SHAP values capture the marginal impact of each feature when it is added to or removed from a subset of features.</p><p>SHAP analysis provides a unified framework for feature importance, feature attribution, and model interpretation. It can be applied to various types of models, including black-box models like deep neural networks, as well as more interpretable models like decision trees or linear regression.</p><p>The output of SHAP analysis is a set of SHAP values for each feature, which can be visualized in different ways, such as bar charts or summary plots. These visualizations help in understanding the relative importance of different features and how they influence the model’s predictions. Positive SHAP values indicate that a feature increases the prediction, while negative values imply a decrease in the prediction. The magnitude of the SHAP value represents the strength of the feature’s influence.</p><p>By using SHAP analysis, machine learning practitioners and researchers can gain insights into the inner workings of complex models, identify important features, detect biases or artifacts in the data, validate the model’s behavior, and explain individual predictions to end-users or stakeholders. Overall, SHAP analysis promotes transparency and interpretability in machine learning models, enhancing trust and understanding in their applications.</p><h3>Interpretability</h3><p>In this we will perform Logistic Regression and Decision Tree initially to get the results and then do SHAP analysis to analyze the results. We will also use AutoML to get the most accurate results like we did before.</p><p>We will use this notebook for understanding</p><p><a href="https://colab.research.google.com/drive/1liBZ0UApdIXjo3zJD-AB57ZE6mxfuY4c?usp=sharing">Google Colaboratory</a></p><p>To fit a linear model to this dataset, we need to first encode the categorical variables using one-hot encoding or dummy variables. Once we have done that, we can use logistic regression to predict the probability of an individual having an income of over 50k based on the independent variables. After fitting the data we get the ROC value of</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*lNpOg9MQaBznv6SUjE8RPA.png" /></figure><p>In general, higher ROC AUC values indicate better classification performance, with values above 0.8 or 0.9 considered excellent. However, the interpretation of “good” or “acceptable” ROC AUC values can vary depending on the specific problem domain and context. It’s important to consider the baseline performance, the distribution of the data, and the specific requirements of the task at hand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y-jRElrAGVVslD84mhJZPw.png" /><figcaption>ROC Curve</figcaption></figure><p>After this we called MinMaxScaler on DecisionTrees to make predictions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*JrFPC3jDMJ1ogsy-XxicWw.png" /></figure><h4>Tuning DecisionTree</h4><p>While this is one of my first times using DecisionTreeClassifier and I’m not sure how to fix all parameters I will try to maximaize accuracy by changing max_depth and min_samples_leaf parameters. I will also check the accuracy of two criterion: gini and entropy. We observe that the best algorithm among Logistic Regression and Decision Tree is Decision Tree having accuracy is<strong> 84.9%.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f5EeVYHlmJvvx4ZdiGGmbg.png" /></figure><p>DecisionTree and LogisticRegression with fixed parameters have the highest accuracy. Moreover, DecisionTree doesn’t need standardized numeric data to work properly. As for DecisionTree, adding parameters increased accuracy by 3,5% in case of LogisticRegression this increase was much smaller. KNeighborsClassifier accuracy is smaller than the rest of algorithms.</p><p>We run AutoML to get the best model so we can predict values from it and do SHAP analysis</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*10bMrABJJrlx8Xd9IsiKoA.png" /></figure><p>We see that Stacked Ensemble is the best model which we saw earlier, jumping on to the predictions part we will go through the Confusion Matrix to check if the data is correct or not</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qgkt_dZtZG14n6dYr15E7A.png" /></figure><p>Seeing the error near to 0 we can safely say that the model is making accurate results.</p><p>The model uses 11 base models, including 4 GBM, 5 XGBoost, and 2 DeepLearning models. The metalearner algorithm used is GLM, with a stacking strategy of cross-validation. The model was trained on a binary classification problem and evaluated using the following metrics on the training data:</p><p>* Mean Squared Error (MSE): 0.07101078470975286</p><p>* Root Mean Squared Error (RMSE): 0.2664784882682894</p><p>* Log Loss: 0.22813993220251944</p><p>* Area Under Curve (AUC): 0.9572730928152918</p><p>* Area Under Precision-Recall Curve (AUCPR): 0.8880622463070198</p><p>* Gini: 0.9145461856305837</p><p>The confusion matrix shows the performance of the model at the optimal threshold (0.3843523015206794) for the F1 score, which is the highest F1 score obtained by the model. At this threshold, the model has an error rate of 10.42%, with 624 false positives and 420 false negatives. The maximum metrics at their respective thresholds are also shown, including the maximum F1 score, F2 score, F0.5 score, accuracy, precision, recall, specificity, absolute MCC, min per-class accuracy, and mean per-class accuracy.</p><h3>SHAP</h3><p>SHAP explanation shows contribution of features for a given instance. The sum of the feature contributions and the bias term is equal to the raw prediction of the model, i.e., prediction before applying inverse link function. H2O implements TreeSHAP which when the features are correlated, can increase contribution of a feature that had no influence on the prediction.</p><h4>SHAP Analysis on Linear Regression</h4><p>In this case, the MAE of the training dataset is 0.262, which means that the model’s predictions are, on average, 0.262 units away from the actual values in the training dataset. The MAE of the test dataset is 0.266, which means that the model’s predictions are, on average, 0.266 units away from the actual values in the test dataset.</p><p>Since the difference between the training and test MAE is relatively small, it suggests that the model is not overfitting and is generalizing well to new data. However, it is always important to evaluate the model’s performance on a variety of metrics and test datasets to ensure that it is robust and reliable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*XEBFXom5XZmw8HW5vbRjJg.png" /></figure><h4>SHAP Analysis on Random Forest Regression</h4><p>This scenario suggests that the model is overfitting the training data. Overfitting occurs when a model learns the training data too well, to the point where it starts to fit to noise or random fluctuations in the data rather than learning the underlying patterns. This often results in a model that performs very well on the training data, but poorly on new data.</p><p>In this case, the training MAE of 0.069 indicates that the model is able to make accurate predictions on the training data, but the test MAE of 0.189 suggests that the model is not generalizing well to new, unseen data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R9CQSZtQ8hRmEyGHvwk_qw.png" /></figure><p>From the above given waterfall model we can see that all the values that are in red will push our income more towards 1.(we have done one hot encoding, meaning that if income &gt;50k then its 1). So we can see that the job roles of “Handlers-cleaners”, and the relationship status as Other relative, as well as the maritial status — “Never-married”, all signify that the income will largely be pushed towards &lt;=50K. While husbands, or relationship — Not in family or single etc, will have maximum number of income.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gOBRiSGlhH-LqpKuImV_6Q.png" /></figure><p>This is a Force Plot, where the red values show the values that will take out data towards income &gt; 50K. Predicted base value we have seen is 1.04, which means that majority of people have income larger than 50k. Majority of people that have an income of larger than 50k, are either husbands, or marital status of married with spouse, or have a relationship as Not in family.</p><h4>SHAP Analysis on Decision tree regressor</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*gQ5zYCiMIfOPa00vDxGrdQ.png" /></figure><p>The above is an example of Beeswarm plots, in SHAP. For each variable, every instance of the dataset appears as its own point. The points are distributed horizontally acording to the SHAP values. In high density areas, the points are stacked vertically. More crowded areas mean that this effects the data more.</p><h3>Conclusion</h3><p>In this analysis, it is evident that the Machine Learning algorithms have performed well, displaying low RMSE and MSE values close to 0. The utilization of an AutoML library has been beneficial, as it has streamlined the process by automating hyperparameter tuning and running the data through multiple algorithms, resulting in highly accurate predictions. Notably, the significance of data cleaning and feature selection has been highlighted. The presence of null values or non-standardized data can lead to erroneous outcomes, and without understanding the relative importance of different features in predicting the desired outcome, achieving high accuracy becomes challenging. For convenience, all the necessary components have been consolidated into a single notebook, providing a comprehensive reference for future analysis.</p><p><a href="https://colab.research.google.com/drive/13JxCC-cWkZBCk6y06bMYsiyz4nLweyES?usp=sharing">Google Colaboratory</a></p><p>Thanks for reading, leave a clap if you liked the article 👏 😃</p><h3>Advisors</h3><p><a href="https://www.linkedin.com/in/nikbearbrown/">Nick Bear Brown</a></p><h3>Authors</h3><p><a href="https://www.linkedin.com/in/jainam-mehta-2a1b68187/">Jainam Meht</a>a<br><a href="https://www.linkedin.com/in/nikbearbrown/">Nick Bear Brown</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=837b51e6d870" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using ChatGPT to create Artworks using DALL-E 2]]></title>
            <link>https://medium.com/@jainamm47/using-chatgpt-to-create-artworks-using-dall-e-2-130fef54288?source=rss-48cc54d4d0e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/130fef54288</guid>
            <dc:creator><![CDATA[Jainam Mehta]]></dc:creator>
            <pubDate>Tue, 28 Mar 2023 05:33:52 GMT</pubDate>
            <atom:updated>2023-03-28T05:33:52.622Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KuiFrXE5tkPgvwBePOXR4A.png" /></figure><h3><strong>Introduction</strong></h3><p>ChatGPT has the ability to generate human-like responses to text prompts. With the development of DALL-E 2, an advanced AI model from OpenAI, ChatGPT can now create unique and original artworks in response to textual input. This exciting development allows for a new level of creativity and innovation, as artists and designers can now use language to communicate their vision to the machine, which can then produce visual representations of their ideas. In this way, ChatGPT and DALL-E 2 are revolutionizing the creative process and opening up new possibilities for artists and designers alike.</p><p>As a result, I’ve compiled a list of my observations on <strong>DALL-E for which I used ChatGPT to produce me a prompt</strong>, accompanied by relevant examples.</p><p>First let us understand what these AI tools are and what they excel at. After that will try to cover various topics and try to run the models to get the best possible outcome.</p><h3>ChatGPT</h3><p>ChatGPT is a large language model developed by OpenAI, based on the Generative Pre-trained Transformer 3.5 architecture. It is trained on an enormous dataset of text from the internet, allowing it to understand and generate human-like language in a variety of contexts. Here are some specific points that ChatGPT excels at:</p><ol><li>Language generation: ChatGPT can generate high-quality, human-like language in a wide range of styles and formats, from casual conversation to academic writing.</li><li>Contextual understanding: ChatGPT is able to understand the context of a given text prompt, and generate responses that are appropriate and relevant to that context.</li><li>Creativity: ChatGPT is capable of generating creative and original responses to text prompts, making it useful for tasks such as creative writing and content generation.</li><li>Language translation: ChatGPT can translate text from one language to another, making it a valuable tool for cross-cultural communication and language learning.</li><li>Question answering: ChatGPT can answer questions posed in natural language, making it useful for tasks such as customer service and information retrieval.</li></ol><h3>Dall-E</h3><p>DALL-E is an advanced AI model developed by OpenAI, designed to generate high-quality images from textual input. It is named after the artist Salvador Dali and the Pixar character WALL-E, reflecting its ability to generate surreal and creative images with a high degree of detail and realism. Here are some specific points that DALL-E excels at:</p><ol><li>Image generation: DALL-E is able to generate high-quality, realistic images from textual input, making it a valuable tool for artists, designers, and other creatives.</li><li>Creative exploration: DALL-E is capable of generating imaginative and surreal images that push the boundaries of traditional art and design, making it a valuable tool for exploring new ideas and concepts.</li><li>Customizability: DALL-E allows for a high degree of customization in the generated images, such as changing the pose, size, and composition of objects within the scene.</li></ol><p>So to create some challenging tasks we will ask ChatGPT to ask for artwork which is hard to imagine and test Dall-E 2 against it to check if it can pass hard challenges. We will try to add multiple elements to make it more challenging. We will try to score the images of how appropriate they are and than take an average to make a conclusion if Dall-E can understand multiple components and create an artwork.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f5bNtnFAZ2gIE_jZqpiB5A.png" /><figcaption>Some challenging tasks suggested by ChatGPT</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mzCmFJlkgxdeYfgox-0Lvw.png" /><figcaption>A pineapple wearing a tutu and playing a guitar on a beach</figcaption></figure><p>Starting with a simple challenge we can see that it was successful we can give it 5/5 as it made perfect artwork.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c7F5AYZiiHLeoi6h1TisrQ.png" /><figcaption>A dragon made of ice, breathing fire</figcaption></figure><p>We can rate this also 5/5 as the images are perfect, the first image was an exceptional artwork as ice is translucent it took that into account and used it as a feature to showcase fire</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OcK8OCRFG-lArD9gGdrgIw.png" /><figcaption>Create an image of a superhero team lineup, featuring original characters with unique powers and costumes.</figcaption></figure><p>We can observe that Dall-E 2 tried to create superheroes but messed up with faces as it tried to generate faces but ended up merging different people faces so we can rate 3.5/5</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k4hyKDjDLCUZwjt3f-_fpQ.png" /><figcaption>create fantasy landscapes, such as those found in epic fantasy novels or video games. This task could involve generating landscapes with mythical creatures, magical forests, and ancient ruins.</figcaption></figure><p>Here Dall-E has referenced famous game maps and layout so we can conclude by saying that it has been successful in generating so we can give a score of 5/5</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T_u-D4KOXwwN_cbJPMA0Gg.png" /><figcaption>generate tower defense games with unique enemy types, tower upgrades, and map layouts. The goal of the game could be to defend a base or objective from waves of enemy attacks.</figcaption></figure><p>As we can say that AI generated a tower defense game having unique enemy types with different map layout while defending the base. As it generated proper images we can give it a score of 5/5.</p><h4><strong>Complicated Ideas</strong></h4><p>We can try to generate movie set ideas using AI that can give directors some new ideas. Lets try this prompt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A0O21qffKYT5VQwuKSmluw.png" /><figcaption>A horror movie set in a haunted hotel where the guests and staff are trapped and must survive the night.</figcaption></figure><p>Checking the 3rd image we see that one of the character is already injured and to survive the other character has to be on alert.</p><p>Lets try to mix characters with different views and check it out</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8uCBnU_JCVavYJQjpNwY4w.png" /><figcaption>John wick at Empire State Building</figcaption></figure><p>We observe that rather than getting exact photo of how John wick looks it tried to get out the main features like long hair and other things. This proves that it tries to optimize on main features.</p><h3>Conclusion</h3><p>In conclusion, the combination of ChatGPT and DALL-E 2 has opened up new possibilities for artists and designers to create unique and original artworks in response to textual input. From simple challenges such as a pineapple playing guitar to more complex challenges such as generating a superhero team lineup or a tower defense game, DALL-E 2 has demonstrated its ability to generate high-quality images that are both creative and relevant to the given context. While there may still be some limitations in certain scenarios, the potential for this technology is exciting and holds promise for the future of creative industries.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=130fef54288" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Different Exchanges of RabbitMQ]]></title>
            <link>https://medium.com/@jainamm47/understanding-different-exchanges-of-rabbitmq-e7d233de0c92?source=rss-48cc54d4d0e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7d233de0c92</guid>
            <category><![CDATA[rabbitmq]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Jainam Mehta]]></dc:creator>
            <pubDate>Fri, 18 Feb 2022 20:22:43 GMT</pubDate>
            <atom:updated>2022-02-18T20:22:43.359Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YfUlEqmKtiC6_76W517sZA.jpeg" /></figure><h3>Introduction</h3><p>Initially, companies start with monolithic architecture that is they try to have every service running in one single machine and follow the Request-Response architecture using HTTP Protocol.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*RP0nuTCvq2AKV4DvFpWDJg.png" /></figure><p>We can see that vertically scaling this would be very costly as you would only scale up for certain services but other services would still not be used much. To solve this problem Microservices architecture was introduced that believes in the concept of distributing work among different services and only scaling up the service that is being used much and scaling down when not needed which makes it cost-efficient. If we have all services in different places we still need them to communicate efficiently cause they can be deployed in some other continent itself.</p><h4>RabbitMQ</h4><p>This tool tries to solve this problem of microservice introduction by the concept of asynchronous messaging among services. If you don&#39;t understand it don&#39;t sweat it after coding it you will be able to understand it clearly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*nxxAFtUzqvXV8JXwUNklIA.png" /></figure><p>The producer sends the message to the broker i.e RabbitMQ which holds the messages till some consumer comes and processes them.</p><p><strong>Aim:</strong> Understand how to create different exchange types provided by rabbitMQ and what is the use case of each type and when to use which one</p><h3>Prerequisites</h3><ol><li>We will be using NodeJS for this tutorial</li><li>Docker for running RabbitMQ or you can locally install from <a href="https://www.rabbitmq.com/download.html">https://www.rabbitmq.com/download.html</a></li></ol><h4>Starting Up RabbitMQ</h4><p>I will be using Docker to start the RabbitMQ container and use it</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e482cce5e86e685bceb01f8f1f9bc9e/href">https://medium.com/media/5e482cce5e86e685bceb01f8f1f9bc9e/href</a></iframe><p>To start the container just type in docker-compose up this will start the rabbitMQ instance and to verify it just go to <a href="http://localhost:15672/">http://localhost:15672</a> and you will see a page and just type guest in username and password that will take you to the admin panel.</p><h3>Hello World</h3><p>This is the most basic type where we will have one publisher and consumer where the consumer subscribes to a specific queue and the publisher sends to a message to that queue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B9BDmSHI5jzjanqKlP81tQ.png" /></figure><p>Enough reading right let&#39;s implement it and test the power of this tool.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2070f9827e3ef4d4343eed2919dfa42/href">https://medium.com/media/f2070f9827e3ef4d4343eed2919dfa42/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fab7daabd412e2fb1e27df6cf6cde4b5/href">https://medium.com/media/fab7daabd412e2fb1e27df6cf6cde4b5/href</a></iframe><p>To run it first type node consumer.js and then node publish.js you will see the following result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bzb76oRrOMmMLp9GpFsgWg.png" /></figure><p>Now let&#39;s understand this, in publisher, we simply create a connection and then connect a channel that connects to the queue basics to which it will publish, and on the consumer side we do the same thing connect the channel to that specific queue and then waits for the message to come so it can start consuming. The main important part is line number 17 on consumer.js cause we need to tell the queue that we have consumed it and now you can delete otherwise it will keep it on hold.</p><h3>Fanout Exchange</h3><p>This is like a broadcasting exchange type where the publisher sends a message using an exchange type called <strong>Fanout </strong>which tells the exchange to send it to all the queues that it is connected to without any filtering. Understand Exchange is like the brain that knows which queue to exactly send to and it is the most important part of rabbitmq system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*nHS85iMZV-2KOQWcSi54SA.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68000bc262ba7a461d7b796ba809e6f4/href">https://medium.com/media/68000bc262ba7a461d7b796ba809e6f4/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3f6348bb230e5116392e53d09b16cfc/href">https://medium.com/media/a3f6348bb230e5116392e53d09b16cfc/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f82ef838d55a2ab479a75f45026e331/href">https://medium.com/media/6f82ef838d55a2ab479a75f45026e331/href</a></iframe><p>If you run these three files you will get such a response</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3DJPe9rowmLKBSmOKgqf0A.png" /></figure><p>In publisher.js we connect our channel to an exchange named notification which has type fanout if you see on line 16. When we publish you would have observed that we also mention the exchange name and a routing key cause that will help the consumer bind to a queue that is connected to the same exchange and routing key which helps it to consume the message that was sent as fanout</p><h3>Direct Exchange</h3><p>Imagine that you are a visa officer applying for requests to US Embassy and Australian Embassy from India. Now one can argue to just send it to direct queue but it would not be efficient you will see when we understand topic exchange after this. Lets just write code first and understand the logic later</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00b75bf416ab7274347b0b42f4aaefc3/href">https://medium.com/media/00b75bf416ab7274347b0b42f4aaefc3/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0dfa6aa18865b4ebedfa4ad9abb54c6b/href">https://medium.com/media/0dfa6aa18865b4ebedfa4ad9abb54c6b/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce792e4118e7c2e5dea27e787a9350d9/href">https://medium.com/media/ce792e4118e7c2e5dea27e787a9350d9/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JSIvhvfMa84G10R9INQyKA.png" /></figure><p>In this publisher, we first send to Australias’ queue using the routing key that sends it to the queue of Australia and the consumer on the other side connects to the same exchange and bind its queue to the exchange with the routing key of <strong>au.syd </strong>which is the same routing key and exchange name that the publisher uses.</p><h3>Topic Exchange</h3><p>This exchange works like regex, the consumer uses symbols to match the routing key coming from the publisher and consumes it. Imagine there was a queue that is only interested in having users related topic and one related payment topic so we will use routing keys in such a manner to consume the messages</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2463085c330baa6f17d42d8a38863c94/href">https://medium.com/media/2463085c330baa6f17d42d8a38863c94/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2463085c330baa6f17d42d8a38863c94/href">https://medium.com/media/2463085c330baa6f17d42d8a38863c94/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da5583b961f1d1797ec1c487366c6420/href">https://medium.com/media/da5583b961f1d1797ec1c487366c6420/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qT714n8V6FyTO-FiAiJCQg.png" /></figure><p>On the consumer side, we use <strong># </strong>specifically to indicate wildcard meaning anything after payments. will be sent to that queue that is validating the regex of this routing key.</p><p>There is also one more exchange called Header Exchange but its not widely used so we can skip it for now. I hope you understood the exchanges the full code has been put on Gihtub</p><p><a href="https://github.com/jainam240101/rabbitMQ-exchanges">GitHub - jainam240101/rabbitMQ-exchanges</a></p><p>If you have any question you can DM me on discord <strong>Jainam#2240 </strong>and if any changes raise an issue or send a PR.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7d233de0c92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to API Development in GoLang- Part 2]]></title>
            <link>https://medium.com/@jainamm47/introduction-to-api-development-in-golang-part-2-62692aa9a4ee?source=rss-48cc54d4d0e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/62692aa9a4ee</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[hexagonal-architecture]]></category>
            <dc:creator><![CDATA[Jainam Mehta]]></dc:creator>
            <pubDate>Sun, 14 Nov 2021 15:44:47 GMT</pubDate>
            <atom:updated>2021-11-14T15:44:47.799Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey Guys 👋<br>In the last blog, we wrote the architecture for creating a hexagonal architecture for our UserModel and wrote a single API route to create a user. I can agree that it was a lot of new concepts in the last blog but you can trust me this one is pretty simple and straightforward. I will link the blog and Github for the first blog so if anyone wants to start from this part can start right away.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*FVCawd3vZPDc0-elJrVR1Q.jpeg" /></figure><ul><li><a href="https://medium.com/@jainamm47/introduction-to-api-development-in-golang-c5dcecc47dd2">Introduction to API Development in GoLang</a></li><li><a href="https://github.com/jainam240101/hexagonal-architecture-blog/tree/1-Introduction">GitHub - jainam240101/hexagonal-architecture-blog at 1-Introduction</a></li></ul><p>In this blog, we will just write Read, Update and Delete Operations for UserModel so it will be pretty easy implementation. As usual, we will first write out our domain object with the Database query then write a service for it and connect it to our handlers to test out the route.</p><p>Update your <strong>UserInterface </strong>in <strong>Users.go</strong></p><pre>type UserRepository interface {</pre><pre>      CreateUser(UserModel) (*UserModel, error)</pre><pre>      FindUserById(string) (*UserModel, error)</pre><pre>      UpdateUser(string, UserModel) (*UserModel, error)</pre><pre>      DeleteUser(string) error</pre><pre>}</pre><p>Now we will define all our domain functions to interact with UserModel</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cff9e0992ef27aeedb03b599c96a9e66/href">https://medium.com/media/cff9e0992ef27aeedb03b599c96a9e66/href</a></iframe><p>We have written three functions that just run the database query with the data we pass to.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32821975a87f31fec23fc23763354200/href">https://medium.com/media/32821975a87f31fec23fc23763354200/href</a></iframe><p>This is our UserServices that contains all the business logic for our UserModel. Our interface consists of the domain pointer that we will use to make connections to do Db queries.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51dfc60b39fba4af6ff4a0e1f41f8e52/href">https://medium.com/media/51dfc60b39fba4af6ff4a0e1f41f8e52/href</a></iframe><p>This is all our user handlers that are connected to our User services with hardcoded userIds which will be replaced with the ids stored in JWT Token once we include authentication we can include the functions where we send the userId to maintain atomic transactions in our db.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/779d466211d39d12b5ceb15299cdee9b/href">https://medium.com/media/779d466211d39d12b5ceb15299cdee9b/href</a></iframe><p>These are all the routes that connect to the handler and expose all our functions.</p><blockquote>All the code has been psuhed to the same github repo. So incase you get stuck you can refer to it</blockquote><p><a href="https://github.com/jainam240101/hexagonal-architecture-blog/tree/2-User-Operations">GitHub - jainam240101/hexagonal-architecture-blog at 2-User-Operations</a></p><p>If you couldn’t understand any part you can DM me over Discord (<strong>Jainam#2240</strong>) at any time, I will reply back soon and help you out. The other blogs will be coming in the coming weeks. We completed the user routes and in the next blog, I will be walking over how to create authentication using JWT and start protecting our routes.</p><p>Thanks for reading, leave a clap if you liked the blog. ✌️✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62692aa9a4ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to API Development in GoLang]]></title>
            <link>https://medium.com/@jainamm47/introduction-to-api-development-in-golang-c5dcecc47dd2?source=rss-48cc54d4d0e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5dcecc47dd2</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[hexagonal-architecture]]></category>
            <dc:creator><![CDATA[Jainam Mehta]]></dc:creator>
            <pubDate>Thu, 14 Oct 2021 13:56:20 GMT</pubDate>
            <atom:updated>2021-10-14T13:56:20.028Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey Guys 👋</p><p>I recently learned GoLang just out of curiosity as it is been widely used by companies all over the world. As any backend developer, I was looking at the features that it exposes to create a fast and scalable API. I came across the concept of creating Microservices in Go in hexagonal architecture. This got me excited and I started digging into it. For those who don&#39;t know what this is, I will link a small article down below just to know what this concept is.</p><p><a href="https://blog.octo.com/en/hexagonal-architecture-three-principles-and-an-implementation-example/">Hexagonal Architecture: three principles and an implementation example</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*FVCawd3vZPDc0-elJrVR1Q.jpeg" /></figure><p><strong>Aim: </strong>A secured Todo API Client.<br>We will use Go Gin as our backend framework (if you are from NodeJS world think of it like Express), PostgreSQL (Database), Redis (Authentication Purposes), JWT, GORM (ORM to integrate with Db)<br>We will try to cover Authentication, Interacting with Databases using ORM, Relations, and a lot of other small topics.</p><blockquote>Note: I assume you have basic knowledge of GoLang as I won’t be explaining those topics. Covering everything in one article will make it boring so will cover all of it in different parts and all the code will be open-sourced on Github in case you get stuck.</blockquote><p><strong>So let&#39;s get started now</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F15800164&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fsilicon-valley-jared-dunn-woo-excited-happy-gif-15800164&amp;image=https%3A%2F%2Fc.tenor.com%2FMvdr4FQCv3EAAAAM%2Fsilicon-valley-jared-dunn.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ebda31b099190d6867680cc30c394e1/href">https://medium.com/media/2ebda31b099190d6867680cc30c394e1/href</a></iframe><p>In this part, we will just focus on understanding how to implement the architecture by writing one simple API Route of creating a user and storing his data in Db</p><p>Install Fresh for hot reload</p><pre>go get github.com/pilu/fresh</pre><p>Create a mod file</p><pre>go mod init github.com/jainam240101/todo</pre><p>Add these Libraries that we will be using throughout the application</p><pre>go get github.com/dgrijalva/jwt-go github.com/gin-gonic/gin  github.com/google/uuid gorm.io/gorm gorm.io/driver/postgres golang.org/x/crypto/bcrypt</pre><p><strong>Folder Structure</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*UZrVcBx56v6CbyL0uL1z0g.png" /></figure><p>Let&#39;s start with creating a UserModel First. Create A Folder in the domain called <strong>Users</strong> and two Files in it called <strong>UserRepositoryDb.go</strong> and <strong>Users.go <br></strong>I will explain the usage of all these files while writing code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55e4c5bf52dac1d67537985b68398e9d/href">https://medium.com/media/55e4c5bf52dac1d67537985b68398e9d/href</a></iframe><p>In this Users.go we are creating our User Model with help of gorm. The<strong> gorm. Model </strong>will automatically create columns of <strong>created_at, updated_at, </strong>and <strong>deleted_at</strong>. It will keep automatically updating it. The <strong>UniqueIndex </strong>is used to keep all elements of that column unique.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8367a3ff9b59ddf2c0f5686cd640e380/href">https://medium.com/media/8367a3ff9b59ddf2c0f5686cd640e380/href</a></iframe><p>Our Database part is done so let&#39;s focus on writing our Service (Business Logic) for Creating a User and running some logic to bcrypt the password for security purposes. Create a file in services called <strong>UserService.go</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/238c964868c1c2970c45b9b818012aba/href">https://medium.com/media/238c964868c1c2970c45b9b818012aba/href</a></iframe><p>In this the NewCustomerService is creating a connection to our UserRepository so that our service handlers can interact with our domain objects. Rest of the things are pretty straightforward.</p><p>Now lets write our handler so that we can test our API.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f26480fb3265b9331c62d4006a2d520/href">https://medium.com/media/6f26480fb3265b9331c62d4006a2d520/href</a></iframe><p>This is our handler that connects to our service (Business Logic) so that we can send the coming data from the postman to our service that will send it to the database to store it and return back with the other fields. We will now create our <strong>UserRoutes.go</strong> file in our <strong>Routes</strong> Folder to declare all our User Routes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7788219188378fd33ce749100e94bf6c/href">https://medium.com/media/7788219188378fd33ce749100e94bf6c/href</a></iframe><p>Line 12 will look a bit complicated to you but let me explain what&#39;s happening here. If you remember we have <strong>NewUserRepositoryDb</strong> and <strong>NewUserService </strong>functions in our domain and services and we have structs declared there. In the NewUserRepositoryDb we send our database connection pointer which the functions will use when called up. In NewUserService we are using the struct of our RepositoryDb which accepts the repository of User as an argument to create a connection with it. At last, we take all the connections and pass them to our handler to wire them up completely.</p><p>Though it seems a bit confusing at times the advantage of this big setup is that we can individually run tests on each component separately and scaling is very easy. In the next APIs, we write we just have to declare function cause the wiring is only done. The setup is time-consuming but saves time for changing logic or changing the query or anything.</p><p>Let&#39;s declare our main function now to expose all our routes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/310725c950676fb490f6cc05ebe421d0/href">https://medium.com/media/310725c950676fb490f6cc05ebe421d0/href</a></iframe><p>All our Code part is done now just enter this command in your terminal to start the server at default port that is <strong>localhost:8080</strong></p><pre>fresh</pre><p>Run the route in postman and send the data accordingly. You can see that our code was pretty fast and ran each and everything in only 21ms. Which is pretty damn fast as our code was converted to a single executable file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XZEr_unC8oOt9imJQuY4cA.png" /><figcaption>Output</figcaption></figure><p>I can understand if you couldn&#39;t understand all the things at once but don&#39;t worry if you complete this whole series of articles by the end you will be pretty comfortable writing such APIs. If you get stuck anywhere i have linked the Github Repository down below you can check it.</p><p><a href="https://github.com/jainam240101/hexagonal-architecture-blog/tree/1-Introduction">GitHub - jainam240101/hexagonal-architecture-blog at 1-Introduction</a></p><p>If you couldn&#39;t understand any part you can DM me over Discord (<strong>Jainam#2240</strong>) at any time, I will reply back soon and help you out. The other blogs will be coming in the coming weeks and now the major setup is done so we will just be writing functions that are easy to understand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*mES041jZ2tUcHkxRMwWV9A.png" /><figcaption>Peace out✌️✌️</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5dcecc47dd2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deployment of your Web Application to a Server.]]></title>
            <link>https://medium.com/@jainamm47/deployment-of-your-web-application-to-a-server-83b0a863aa66?source=rss-48cc54d4d0e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/83b0a863aa66</guid>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[deploy]]></category>
            <dc:creator><![CDATA[Jainam Mehta]]></dc:creator>
            <pubDate>Fri, 17 Apr 2020 13:05:15 GMT</pubDate>
            <atom:updated>2020-04-17T13:05:15.182Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello Folks lets start my asking yourself a Question like we build a website and now its time of deployment what feeling to we get maybe something this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r_MTqmI0zgyTeePZjXyV4Q.jpeg" /><figcaption>Gilfoyle coding Anton to hack a Fridge (Silicon Valley)</figcaption></figure><p>But that is Gilfoyle, like not everyone can create a server at home and use ,so lets get to the real stuff and deploy our site. We gonna use firebase to host out code and connect a domain to firebase. So these are the steps we follow</p><ul><li>Install npm(Node.js) in our System</li><li>Download Firebase tools globally</li><li>Set up firebase login and deploy the directory on firebase</li><li>Set up a custom domain (for this I am gonna use Freenom)</li></ul><p>Alright let start it now.</p><p>1- We will install Node.Js from the following link</p><p><a href="https://nodejs.org/en/download/">Node.js - Download Node.js®</a></p><p>Set it up and you are done. You can try checking by opening your terminal and writing “<strong>node</strong>” in it and type some <strong>JavaScript </strong>and if it runs you ready to go to the next step.</p><p>2- So you will need to have a Google account as Firebase is og Google. Than go to the following link</p><p><a href="https://firebase.google.com/">Firebase | Google&#39;s Mobile and Web App Development Platform</a></p><p>Click on <strong>Go to Console </strong>and there click on “Create a Project” and put your project name and your project will be created. So after creating your project go to your terminal and type the following command.</p><pre>npm i -g firebase-tools</pre><p>Let it install and then type the the following line.</p><pre>firebase login</pre><p>This will open your browser and you have to <strong>select the account in which you created a firebase project. </strong>After that go to your project folder and see that if you have a “<strong>package.json</strong>” and it has firebase tools than you are good otherwise you have create a dependency there by typing the following command on your project folder.</p><pre>npm i --save firebase-tools</pre><p>Than it will create a dependency there. After installing we intialize firebase by typing the command on our project folder terminal</p><pre>firebase init</pre><p>You have to select the option “<strong>Hosting: Configure and deploy Firebase Hosting sites</strong>” by clicking space bar and than press enter.</p><p>It asks which directory you wanna host and you out in your directory name which consists of all your Files (HTML,CSS,JS,PHP,etc) and than proceed.</p><p>It asks if it can rewrite the URLs of “index.html” and just click no in all options.</p><p>After everything is done you are back to terminal so you type in</p><pre>firebase deploy</pre><p>After running that command it deploys your project to web and gives you your project URL which shows that it is deployed on that link. You can check it by opening that link. We see that project is hosted on Firebase now we will add our Custom domain to it.</p><p>3- Go this website and create your choice domain just by creating an acoount and putting your desired website name</p><p><a href="https://www.freenom.com/en/index.html?lang=en">Freenom - A Name for Everyone</a></p><p>After you are done with accounts and everything go to Firebase Hosting dashboard and click on Custom Domain and put in the URL that you created in freenom. Click on Next and it will show you that two values that will be server ip addresses. You do the following steps for both of the values.</p><ul><li>Go back to freenom and go to <strong>Services </strong>than <strong>My Domains </strong>and than <strong>Manage Domain </strong>and than on <strong>DNS MANAGEMENT</strong></li><li>It shows you something Record and all.</li><li>Paste the value of IP address on the Value Option in Freenom and Type as “A” and save record</li><li>Do this for both the values and save them</li></ul><p>Alright so you are Done, In Firebase you can click on verify and than it connects to your Desired URL and you are done . You can see the value “Connected” in front of your URL in Firebase.</p><p>Yeah I know that these are so many steps and its a bit complicated but cant help it unless you are capable of creating your own Home Server you have to use these third party services for the sake of doing it.</p><p>Alright Guys we are done and if you have any Query you can mail me on “jainamm47@gmail.com” will reply you soon.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83b0a863aa66" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Real Time Predictions on Convolutional Neural Network]]></title>
            <link>https://medium.com/@jainamm47/real-time-predictions-on-convolutional-neural-network-f0663de7e73?source=rss-48cc54d4d0e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0663de7e73</guid>
            <category><![CDATA[convolutional-network]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Jainam Mehta]]></dc:creator>
            <pubDate>Tue, 14 Jan 2020 05:20:20 GMT</pubDate>
            <atom:updated>2020-01-14T05:20:20.252Z</atom:updated>
            <content:encoded><![CDATA[<p>In todays’ time the truth about Machine Learning or Deep Learning is that everyone wants to learn it but the problem is :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*xPhZtQSdDQP_m_jEa783Gw.jpeg" /></figure><p>Well not just OCR but for most of the things. Well today i will teach you how to do Real Time Predictions and Predictions on a Loaded Image.</p><p>All right lets Buckle Up for some cool stuff and enough of Theory Lectures.</p><h3><strong>Make Predictions on A Loaded Image</strong></h3><p>The required libraries are</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*z9G6J8A_Mr0xQ6EUA8vwzA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*VEwaEHeWX0ys4ob8dQHCAg.jpeg" /></figure><ol><li>Tensorflow</li><li>OpenCV</li><li>Keras</li></ol><p>You can download them using pip command and even with a .whl file.</p><p>After Training Model Run the following code which will save your Machine Learning Model</p><pre>model.save(&quot;MODEL_NAME.model&quot;)</pre><p>This command will save your model in the current working directory where your code is pasted. Now download an image that you want your model to predict and place it on the current working directory and paste the following code.</p><pre>import tensorflow as tf<br>import cv2</pre><pre>labels=[] #Create A List Of Labels that Your model Is trained eg: Cats,Dogs,etc<br>def prepare(filepath):<br>    img_size= #You enter the number of Your Input Shape<br>    img_array=cv2.imread(filepath,cv2.IMREAD_GRAYSCALE)<br>    new_array=cv2.resize(img_array,(img_size,img_size))<br>    return new_array.reshape(-1,img_size,img_size,1)</pre><pre>model=tf.keras.models.load_model(&#39;Your_Model_Name.model&#39;)<br>prediction=model.predict([prepare(&#39;Your_Image_Name&#39;)])<br>print(prediction)</pre><p>So your prediction probability of all the labels would be printed here and than the index with highest probability is what your Machine Learning model predicted.</p><h3>Real Time Predictions Using Flask,Open CV</h3><p>The Required libraries for Real Time Prediction are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*8AL_9Za0qD8rNi9pmtreuw.jpeg" /></figure><ol><li>Flask</li><li>OpenCV</li><li>Numpy</li><li>Respective XML File for your prediction but the one I used for prediction is “haarcascade_frontalface_default.xml” which is easily available on Web</li></ol><p>Create a folder and put the 3 code blocks and run the “main.py”. You should also have your model in the same folder with you models JSON file present in the same folder.</p><p>This below code is the code where your model is loaded and the prediction is made. You can save it with the name “model.py”</p><pre>from keras.models import model_from_json<br>import numpy as np</pre><pre>class FacialExpressionModel(object):</pre><pre>labels = []# Your Labels List<br>    def __init__(self, model_json_file, model_weights_file):<br>        # load model from JSON file<br>        with open(model_json_file, &quot;r&quot;) as json_file:<br>            loaded_model_json = json_file.read()<br>            self.loaded_model = model_from_json(loaded_model_json)</pre><pre># load weights into the new model<br>        self.loaded_model.load_weights(model_weights_file)<br>        self.loaded_model._make_predict_function()</pre><pre>def predict_emotion(self, img):<br>        self.preds = self.loaded_model.predict(img)<br>        return FacialExpressionModel.labels[np.argmax(self.preds)]</pre><p>The next Code you will be pasting is the one that initiates your VideoCamera to make real time predictions. The XML should be also kept in the current Directory. So this code will draw the box around the object and write what is it predicting.</p><pre>import cv2<br>from model import FacialExpressionModel<br>import numpy as np</pre><pre>facec = cv2.CascadeClassifier(&#39;haarcascade_frontalface_default.xml&#39;)<br>model = FacialExpressionModel(&quot;model.json&quot;, &quot;model_weights.h5&quot;)<br>font = cv2.FONT_HERSHEY_SIMPLEX</pre><pre>class VideoCamera(object):<br>    def __init__(self):<br>        self.video = cv2.VideoCapture(0)</pre><pre>def __del__(self):<br>        self.video.release()</pre><pre># returns camera frames along with bounding boxes and predictions<br>    def get_frame(self):<br>        _, fr = self.video.read()<br>        gray_fr = cv2.cvtColor(fr, cv2.COLOR_BGR2GRAY)<br>        faces = facec.detectMultiScale(gray_fr, 1.3, 5)</pre><pre>for (x, y, w, h) in faces:<br>            fc = gray_fr[y:y+h, x:x+w]</pre><pre>roi = cv2.resize(fc, (48, 48))<br>            pred = model.predict_emotion(roi[np.newaxis, :, :, np.newaxis])</pre><pre>cv2.putText(fr, pred, (x, y), font, 1, (255, 255, 0), 2)<br>            cv2.rectangle(fr,(x,y),(x+w,y+h),(255,0,0),2)</pre><pre>_, jpeg = cv2.imencode(&#39;.jpg&#39;, fr)<br>        return jpeg.tobytes()</pre><p>Final Step: We will use Flask to put both of the code on Browser and we will test our model .</p><p>Before that create a folder named Templates with a html page in that named “index.html” You can change its name but that you will have to keep your given name in main.py instead of index.html.</p><p>The code for index.html is</p><pre>&lt;<strong>html</strong>&gt;</pre><pre>&lt;<strong>head</strong>&gt;</pre><pre>&lt;<strong>title</strong>&gt;Face expression recognition&lt;/<strong>title</strong>&gt;</pre><pre>&lt;/<strong>head</strong>&gt;</pre><pre>&lt;<strong>body</strong>&gt;</pre><pre>&lt;<strong>img</strong> id=&quot;bg&quot; width=1200px height=900px src=&quot;<em>{{ url_for(&#39;video_feed&#39;) }}</em>&quot;&gt;</pre><pre>&lt;/<strong>body</strong>&gt;</pre><pre>&lt;/<strong>html</strong>&gt;</pre><p>The Code for main.py is given below just copy it and run it</p><pre>from flask import Flask, render_template, Response<br>from camera import VideoCamera</pre><pre>app = Flask(__name__)</pre><pre><a href="http://twitter.com/app">@app</a>.route(&#39;/&#39;)<br>def index():<br>    return render_template(&#39;index.html&#39;)</pre><pre>def gen(camera):<br>    while True:<br>        frame = camera.get_frame()<br>        yield (b&#39;--frame\r\n&#39;<br>               b&#39;Content-Type: image/jpeg\r\n\r\n&#39; + frame + b&#39;\r\n\r\n&#39;)</pre><pre><a href="http://twitter.com/app">@app</a>.route(&#39;/video_feed&#39;)<br>def video_feed():<br>    return Response(gen(VideoCamera()),<br>                    mimetype=&#39;multipart/x-mixed-replace; boundary=frame&#39;)</pre><pre>if __name__ == &#39;__main__&#39;:<br>    app.run(host=&#39;0.0.0.0&#39;)</pre><p>After running the above code you Python will create a localhost server on port 5000 so type this on your web to open your Camera for predictions.</p><pre>localhost:5000</pre><p>I hope you have got it right and if you face any problem you can contact me at</p><p><strong>jainamm47@gmail.com</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0663de7e73" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multiple Linear Regression Using Backward Elimination using Python]]></title>
            <link>https://medium.com/@jainamm47/multiple-linear-regression-using-backward-elimination-using-python-10dfe4104969?source=rss-48cc54d4d0e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/10dfe4104969</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[backward-elimination]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[linear-regression]]></category>
            <dc:creator><![CDATA[Jainam Mehta]]></dc:creator>
            <pubDate>Sun, 15 Dec 2019 08:05:53 GMT</pubDate>
            <atom:updated>2019-12-15T08:05:53.387Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello Folks so today I will tell you how to perform Multiple Linear Regression using Python. So this is basically a hands on session and lets get started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gk_2yq6xSulS6wmixaeAMQ.jpeg" /></figure><p>So this is a Startups Dataset with column Research &amp; Development Research, Administration, Marketing Spend, State and Profit. So the independent variables (X) we consider columns from R&amp;D Spend till State and we consider Profit as dependent variable.</p><p><a href="https://drive.google.com/open?id=1reqVgbFljyJUo2XraEJWaBd89DVUSPYS">50_Startups.csv</a></p><p>First of all we need to import computing Libraries Pandas, Numpy and Matplotlib as usual and separate the independent and dependent variables.</p><pre>import pandas as pd<br>import numpy as np <br>import matplotlib.pyplot as plt</pre><pre>dataset=pd.read_csv(&quot;50_Startups.csv&quot;)<br>X=dataset.iloc(:,:-1).values#Independent variables data Imported<br>y=dataset.iloc(:,:4).values#Dependent Variables Data Imported</pre><p>We see that in States column it is String value not Integer value so we need to convert String variables to Dummy Variable by preprocessing it. So after Preprocessing we would see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*MHnz7O-TRJpvEuDXXD61kw.png" /><figcaption>Screenshot of the Columns</figcaption></figure><p>So let see what happened. We had 3 states “New York” , “California”, ”Florida” so what we did made 3 column of them and if in that Specific Row if that state is there we place its value as 1 and others as 0. We see in first row the state is New York so 3rd Column which is New York so we we have 1 in that and rest is 0 and all the data of states get filtered that way . So after this preprocessing we can fit these values to our Machine Learning Model.</p><p>Now lets see the code to do the preprocessing of the states column:</p><pre>from sklearn.preprocessing import LabelEncoder,OneHotEncoder<br>labelx=LabelEncoder()#This class converts the states to its unique Value of 0,1,2,.. <br>X[:,3]=labelx.fit_transform(X[:,3])<br>hotencoder=OneHotEncoder(categorical_features=[3])#Here we had 3 States thats why it is 3 but if you have more than change it<br>X=hotencoder.fit_transform(X).toarray()</pre><p>These dummy variable comes with a trap that you can understand by searching on google but to solve it we do a simple trick that is we only take n-1 columns that is we remove last column and if a data row has value 1 in last row than we can observe that rest n-1 columns will have 0 value so the mathematically the weights of the n-1 columns will be neglected.To avoid the trap is simple just use this line of code</p><pre>X=X[:,1:]</pre><p>Now we have to evaluate which independent Variables to keep and which variables not to keep by help of R Squared and Normalization .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/286/1*1gJbdIWTESnF0Ekwny8FWg.png" /><figcaption>R-Squared Formula</figcaption></figure><p>More the R Squared converges to value 1 than we can say that our model is getting evaluated properly. We have to understand following steps</p><ol><li>Select a Significance Level (SL: 0.05) we consider this as it is a general Significance Level</li><li>Fit the Model with all variables</li><li>Consider the highest P-Value and if P&gt;SL than remove that variable having such high P Value</li><li>Remove the Predicator</li><li>Fit the Model with the independent Variable</li></ol><p>It might look a bit confusing but bear it it is not too hard. While doing such steps we have to take care of the Average R-Squared cause sometimes there are cases where P value maybe higher than SL but if we remove than we see that Average R-Squared doesnt converge it diverges and it is not good so we have to take care.</p><p>So lets see the coding part and you will understand it</p><pre>import statsmodel.api as sm<br>X=np.append(arr=np.ones((50,1)).astype(int),values=X,axis=1)<br>X_opt=X[:,[0,1,2,3,4,5]]<br>regressor_ols=sm.OLS(endog=y,exog=X_opt).fit()<br>regressor_ols.summary()</pre><p>When we run this code we will get this table</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*w93A4jrg95UqfgCPYBfcEQ.png" /></figure><p>Here we see variable x2 that is variable 2 has highest P value so we remove it and perform the code again</p><pre>import statsmodel.api as sm<br>X=np.append(arr=np.ones((50,1)).astype(int),values=X,axis=1)<br>X_opt=X[:,[0,1,3,4,5]]<br>regressor_ols=sm.OLS(endog=y,exog=X_opt).fit()<br>regressor_ols.summary()</pre><p><strong>We observe that we after this we will remove variable 3 also and get left with x3,x4 and x5. We Keep eliminating until we have Variables [0,3,5].When you run above code with these variables we get this table</strong></p><p>You code with ommited variables should be like this</p><pre>X_opt=X[:,[0,3,5]]<br>regressor_ols=sm.OLS(endog=y,exog=X_opt).fit()<br>regressor_ols.summary()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*2tlhL33Ug7yQDTiyDPgl9w.png" /></figure><p>As i said that P cant be greater than 0.05 but the variable x2 has 0.060 but if we try to see that if we remove than Average R Squared will start to diverge and its value will become 0.945 which is a big change so we keep these variables to fit our model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*qK_9r-B5VUuZUv7nunCMGw.png" /><figcaption>This is our X with optimized variables</figcaption></figure><p>Now we just have to fit our model and make Predictions:</p><pre>from sklearn.linear_model import LinearRegression<br>from sklearn.model_selection import train_test_split</pre><pre>X_train,X_test,y_train,y_test=train_test_split(X_opt,y,test_size=0.2,random_state=0)<br>new_model=LinearRegression()<br>new_model.fit(X_train,y_train)</pre><p>Our Model is Ready for our prediction so lets see the result</p><pre>y_pred=new_model.predict(X_test)</pre><p>We see our Predictions made and if you want to test your model to new data than make an array and put instead of X_test by using the code</p><pre>test_array=np.array([[1,165349,471784]])<br>print(new_model.predict(test_array))</pre><p>You can change the values of the array according to your means and the predicted value that model gave is <strong>192112.71758056 </strong>and the Actual value was <strong>192262 </strong>so we see our Model was quite accurate and you can play around with it.</p><p>Thank You for reading it and I hope the best that you got everything and if you still face and problem than you can write me at jainamm47@gmail.com.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10dfe4104969" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>