Python implementation of Univariate Analysis
We can use scipy library to implement various mathematical functions. In our implementation, we will use minimize_scalar from the scipy optimize module to find the optimum function value of a custom-defined objective function.
Python3
import numpy as np from scipy.optimize import minimize_scalar # Define the objective function def objective_function(x): return x * * 2 + 3 * x + 2 # Minimize the objective function result = minimize_scalar(objective_function) # Extract the optimal value # and corresponding function value optimal_value = result.x optimal_function_value = result.fun # Print the results print ( "Optimal value:" , optimal_value) print ( "Optimal function value:" , optimal_function_value) |
Output:
Optimal value: -1.5000000000000002 Optimal function value: -0.25
Uni-variate Optimization – Data Science
Optimization is an important part of any data science project, with the help of optimization we try to find the best parameters for our machine learning model which will give the minimum loss value. There can be several ways of minimizing the loss function, However, generally, we use variations of the gradient method for our optimization. In this article, we will discuss univariate optimization.
Contact Us