<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: SyedKashifNaqvi</title>
    <description>The latest articles on DEV Community by SyedKashifNaqvi (@syedkashifnaqvi).</description>
    <link>https://dev.to/syedkashifnaqvi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F958175%2F6ef3b11c-92ad-403a-a4b7-9512ae0add5c.jpeg</url>
      <title>DEV Community: SyedKashifNaqvi</title>
      <link>https://dev.to/syedkashifnaqvi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/syedkashifnaqvi"/>
    <language>en</language>
    <item>
      <title>Machine learning with Django and React.js</title>
      <dc:creator>SyedKashifNaqvi</dc:creator>
      <pubDate>Thu, 02 Mar 2023 05:25:20 +0000</pubDate>
      <link>https://dev.to/syedkashifnaqvi/machine-learning-with-django-and-reactjs-26ln</link>
      <guid>https://dev.to/syedkashifnaqvi/machine-learning-with-django-and-reactjs-26ln</guid>
      <description>&lt;p&gt;This is for begineers guide&lt;/p&gt;

&lt;p&gt;First, let's create a Django project and app and install the necessary dependencies. Open your terminal and run the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Create a new virtual environment (optional)
python -m venv env
source env/bin/activate

# Install Django and other dependencies
pip install django djangorestframework pandas scikit-learn joblib
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, let's create a new Django project and app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;django-admin startproject myproject
cd myproject
python manage.py startapp myapp


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's create a machine learning model that we want to expose through the API. For this example, we'll create a simple logistic regression model that predicts whether a person is male or female based on their height and weight. Create a new file called &lt;code&gt;model.py&lt;/code&gt; in the &lt;code&gt;myapp&lt;/code&gt; directory with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pandas as pd
from sklearn.linear_model import LogisticRegression
import joblib

# Load the training data
data = pd.read_csv('https://people.sc.fsu.edu/~jburkardt/data/csv/hw_200.csv')

# Train a logistic regression model
X = data[['Height', 'Weight']]
y = data['Gender']
model = LogisticRegression()
model.fit(X, y)

# Save the model to disk
joblib.dump(model, 'model.pkl')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code loads a dataset of height and weight measurements and gender labels, trains a logistic regression model using scikit-learn, and saves the trained model to disk using the joblib library.&lt;/p&gt;

&lt;p&gt;Now, let's create a Django view that uses the trained model to make predictions. Create a new file called &lt;code&gt;views.py&lt;/code&gt; in the &lt;code&gt;myapp&lt;/code&gt; directory with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
import joblib
import numpy as np

# Load the saved model from disk
model = joblib.load('model.pkl')

# Define a view that takes input data and returns a prediction
@csrf_exempt
def predict(request):
    if request.method == 'POST':
        # Get the input data from the request
        data = request.POST.dict()

        # Convert the input data to a numpy array
        X = np.array([[float(data['height']), float(data['weight'])]])

        # Use the model to make a prediction
        y_pred = model.predict(X)

        # Return the prediction as a JSON response
        return JsonResponse({'prediction': str(y_pred[0])})
    else:
        return JsonResponse({'error': 'Invalid request method'})


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code defines a view called &lt;code&gt;predict&lt;/code&gt; that takes input data (height and weight) from a POST request, converts the input data to a numpy array, uses the trained model to make a prediction, and returns the prediction as a JSON response.&lt;/p&gt;

&lt;p&gt;Now, let's create a URL pattern that maps the &lt;code&gt;predict&lt;/code&gt; view to a URL. Create a new file called &lt;code&gt;urls.py&lt;/code&gt; in the myapp directory with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.urls import path
from .views import predict

urlpatterns = [
    path('predict/', predict, name='predict'),
]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code defines a URL pattern that maps the &lt;code&gt;/predict/&lt;/code&gt; URL to the predict view.&lt;/p&gt;

&lt;p&gt;Finally, let's start the Django development server to test our API. Run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python manage.py runserver


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Django development server, which will listen for requests on &lt;code&gt;http://127.0.0.1:8000/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now that we have a functioning backend API, let's move on to the React frontend.&lt;/p&gt;

&lt;p&gt;React Frontend&lt;/p&gt;

&lt;p&gt;First, let's create a new React app using &lt;code&gt;create-react-app&lt;/code&gt;. Open your terminal and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app myapp
cd myapp


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's install the necessary dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install axios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This installs the &lt;code&gt;axios&lt;/code&gt; library, which we'll use to make requests to the Django backend API.&lt;/p&gt;

&lt;p&gt;Next, let's create a form component that allows the user to input their height and weight and make a prediction using the backend API. Create a new file called &lt;code&gt;PredictionForm.js&lt;/code&gt; in the src directory with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from 'react';
import axios from 'axios';

function PredictionForm() {
  const [height, setHeight] = useState('');
  const [weight, setWeight] = useState('');
  const [prediction, setPrediction] = useState('');

  const handleSubmit = async (event) =&amp;gt; {
    event.preventDefault();

    try {
      const response = await axios.post('/api/predict/', {
        height: height,
        weight: weight,
      });

      setPrediction(response.data.prediction);
    } catch (error) {
      console.error(error);
    }
  };

  return (
    &amp;lt;form onSubmit={handleSubmit}&amp;gt;
      &amp;lt;label&amp;gt;
        Height (cm):
        &amp;lt;input
          type="number"
          value={height}
          onChange={(event) =&amp;gt; setHeight(event.target.value)}
        /&amp;gt;
      &amp;lt;/label&amp;gt;
      &amp;lt;br /&amp;gt;
      &amp;lt;label&amp;gt;
        Weight (kg):
        &amp;lt;input
          type="number"
          value={weight}
          onChange={(event) =&amp;gt; setWeight(event.target.value)}
        /&amp;gt;
      &amp;lt;/label&amp;gt;
      &amp;lt;br /&amp;gt;
      &amp;lt;button type="submit"&amp;gt;Predict&amp;lt;/button&amp;gt;
      {prediction &amp;amp;&amp;amp; &amp;lt;p&amp;gt;Prediction: {prediction}&amp;lt;/p&amp;gt;}
    &amp;lt;/form&amp;gt;
  );
}

export default PredictionForm;




&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code defines a form component that allows the user to input their height and weight and make a prediction using the backend API. The &lt;code&gt;handleSubmit&lt;/code&gt; function makes a POST request to the &lt;code&gt;/api/predict/&lt;/code&gt; URL using the &lt;code&gt;axios&lt;/code&gt; library, passing the height and weight data as JSON. If the request is successful, the &lt;code&gt;prediction&lt;/code&gt; state is updated with the predicted gender.&lt;/p&gt;

&lt;p&gt;Now, let's create a main component that renders the PredictionForm component. In &lt;code&gt;App.js&lt;/code&gt; in the &lt;code&gt;src&lt;/code&gt; directory with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import PredictionForm from './PredictionForm';

function App() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Gender Predictor&amp;lt;/h1&amp;gt;
      &amp;lt;PredictionForm /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default App;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code defines a main component that renders the &lt;code&gt;PredictionForm&lt;/code&gt; component and a header.&lt;/p&gt;

&lt;p&gt;Finally, let's start the React development server to test our app. Run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`npm start`

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should start the React development server, which will listen for requests on &lt;code&gt;http://localhost:3000/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you navigate to &lt;code&gt;http://localhost:3000/&lt;/code&gt; in your web browser, you should see a form that allows you to input your height and weight and make a prediction using the backend API.&lt;/p&gt;

&lt;p&gt;That's it! You now have a basic Django backend that exposes a machine learning model through a RESTful API, and a React frontend that communicates with the backend to make predictions using the model.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>python3.11 latest changes</title>
      <dc:creator>SyedKashifNaqvi</dc:creator>
      <pubDate>Mon, 09 Jan 2023 09:05:19 +0000</pubDate>
      <link>https://dev.to/syedkashifnaqvi/python311-latest-changes-2411</link>
      <guid>https://dev.to/syedkashifnaqvi/python311-latest-changes-2411</guid>
      <description>&lt;p&gt;brief overview of some of the latest changes and features in Python 3.11:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Time Functions with Nanosecond Resolution: Python 3.11 introduces a new set of time functions with nanosecond resolution. These functions include &lt;code&gt;time.perf_counter_ns(), time.process_time_ns()&lt;/code&gt;, and &lt;code&gt;time.monotonic_ns()&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Positional-Only Parameters: Python 3.11 introduces a new syntax for defining positional-only parameters in function definitions. Positional-only parameters are parameters that can only be specified using their position, and not by using their name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;New Dictionary Methods: Python 3.11 introduces several new methods for dictionaries, including &lt;code&gt;dict.fromkeys_ex()&lt;/code&gt;, which allows you to create a new dictionary with a set of keys and a default value for all of the keys.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Improved Error Handling: Python 3.11 includes several improvements to error handling, including the ability to specify a traceback message when raising an exception, and the ability to specify a from_cause parameter when raising an exception from another exception.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Improved Performance: Python 3.11 includes several performance improvements, including faster dict lookups and faster attribute access.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>productivity</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Search custom form with post request datatable</title>
      <dc:creator>SyedKashifNaqvi</dc:creator>
      <pubDate>Fri, 28 Oct 2022 12:24:10 +0000</pubDate>
      <link>https://dev.to/syedkashifnaqvi/search-custom-form-with-post-request-datatable-8nn</link>
      <guid>https://dev.to/syedkashifnaqvi/search-custom-form-with-post-request-datatable-8nn</guid>
      <description>&lt;p&gt;Hello everyone can i search with post request in data-tables?&lt;/p&gt;

&lt;p&gt;backend -&amp;gt; django&lt;br&gt;
frontend -&amp;gt; html/css jquery&lt;/p&gt;

&lt;p&gt;please guide me i see in data-tables no option for post searching if you know any way please let me know&lt;/p&gt;

</description>
      <category>datatable</category>
    </item>
  </channel>
</rss>
