Disable wermgr.exe on Windows

Using Services

  1. Press Win + R to open the Run dialog.
  2. Type services.msc and press Enter.
  3. Scroll down and locate the Windows Error Reporting Service.
  4. Right-click on it and choose Properties.
  5. In the Startup type dropdown, select Disabled.
  6. Click Apply and then OK.

Using Registry Editor

  1. Press Win + R to open the Run dialog.
  2. Type regedit and press Enter.
  3. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting.
  4. Create a new DWORD value named Disabled and set its value to 1.

 

Ignoring SSL certificate errors in C# RestSharp Library

//bypass ssl validation check by using RestClient object
var options = new RestClientOptions(baseurl) {
    RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
};
var restClient = new RestClient(options);

or in application level

//bypass ssl validation check globally for whole application.
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

 

Ignoring SSL certificate errors in C# HttpClient

var handler = new HttpClientHandler();
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
handler.ServerCertificateCustomValidationCallback = 
    (httpRequestMessage, cert, cetChain, policyErrors) =>
{
    return true;
};

var client = new HttpClient(handler);

 

Preferred Challenges for Certbot

The preferred challenges for Certbot are usually one of the following:

  1. HTTP-01 Challenge: This is the most common challenge type. Certbot will create a temporary file on your web server, and the Let’s Encrypt servers will try to access that file over HTTP. You’ll need to make sure that port 80 is open and that your web server is configured to serve files from the hidden .well-known directory.
  2. DNS-01 Challenge: This challenge requires you to add a specific DNS TXT record to your domain’s DNS settings. This is often used when you need to obtain a wildcard certificate or when the HTTP challenge is not suitable. It might require manual intervention if you don’t have a DNS provider with an API that Certbot can use.
  3. TLS-ALPN-01 Challenge: This challenge requires setting up a special TLS certificate on your server and is less commonly used. It’s generally more complex to set up compared to the HTTP-01 challenge.

The HTTP-01 challenge is often the easiest to use, especially for standard web server setups, while the DNS-01 challenge is necessary for more complex scenarios like wildcard certificates.

You can specify the challenge type when running Certbot with the --preferred-challenges option, followed by the challenge type, such as:

certbot --preferred-challenges http

or

certbot --preferred-challenges dns

Keep in mind that depending on your specific setup and requirements, you might need to choose a specific challenge type or follow additional steps to successfully obtain a certificate.

Certbot Standalone Mode

sudo certbot certonly --standalone --preferred-challenges http -d example.com

When you run this command, Certbot will start a temporary web server on port 80 (unless specified otherwise) and will respond to the HTTP-01 challenge from Let’s Encrypt. Once the challenge is successfully completed, Certbot will obtain the certificate and save it to a location on your system.

Note that since the command uses the --standalone option, you’ll need to make sure that port 80 is not in use by any other service at the time you run the command, and you’ll also need to manually configure your web server to use the obtained certificate once it’s issued.

Modifying the column names of a Pandas DataFrame

Rename Specific Columns

import pandas as pd

# Create a DataFrame
df = pd.DataFrame({
    'Name': ['Alice', 'Bob'],
    'Age': [25, 30]
})

# Rename the 'Name' column to 'Full Name' and 'Age' to 'Age in Years'
df.rename(columns={'Name': 'Full Name', 'Age': 'Age in Years'}, inplace=True)

print(df)

Modify All Headers at Once

# Create a DataFrame
df = pd.DataFrame({
    'Name': ['Alice', 'Bob'],
    'Age': [25, 30]
})

# New column names
new_columns = ['Full Name', 'Age in Years']

# Assign the new column names to the DataFrame
df.columns = new_columns

print(df)

Apply a Function to Headers

# Create a DataFrame
df = pd.DataFrame({
    'Name': ['Alice', 'Bob'],
    'Age': [25, 30]
})

# Make all column names uppercase
df.columns = df.columns.str.upper()

print(df)

 

Remove Column from DataFrame in Pandas

import pandas as pd

# Create a DataFrame
df = pd.DataFrame({
    'Name': ['Alice', 'Bob', 'Charlie'],
    'Age': [25, 30, 35],
    'City': ['New York', 'Los Angeles', 'Chicago']
})

# Print the original DataFrame
print("Original DataFrame:")
print(df)

# Remove the 'Age' column
df = df.drop(columns=['Age'])

# Print the updated DataFrame
print("\nDataFrame After Removing 'Age' Column:")
print(df)

Remember to assign the result back to the DataFrame (or to a new variable) if you want to keep the change. If you just want to remove the column temporarily for a specific operation, you can use the inplace=True argument to modify the DataFrame in place:

df.drop(columns=['Age'], inplace=True)

You can remove a column from a DataFrame by its index

import pandas as pd

# Create a DataFrame
df = pd.DataFrame({
    'Name': ['Alice', 'Bob', 'Charlie'],
    'Age': [25, 30, 35],
    'City': ['New York', 'Los Angeles', 'Chicago']
})

# Print the original DataFrame
print("Original DataFrame:")
print(df)

# Index of the column to be removed
column_index = 1

# Get the name of the column at the specified index
column_name = df.columns[column_index]

# Drop the column by its name
df.drop(columns=[column_name], inplace=True)

# Print the updated DataFrame
print("\nDataFrame After Removing Column at Index 1:")
print(df)

Remove multiple columns at once from a DataFrame in Pandas

import pandas as pd

# Create a DataFrame
df = pd.DataFrame({
    'Name': ['Alice', 'Bob', 'Charlie'],
    'Age': [25, 30, 35],
    'City': ['New York', 'Los Angeles', 'Chicago'],
    'Country': ['USA', 'USA', 'USA']
})

# Print the original DataFrame
print("Original DataFrame:")
print(df)

# List of columns to be removed
columns_to_remove = ['Age', 'Country']

# Drop the specified columns
df.drop(columns=columns_to_remove, inplace=True)

# Print the updated DataFrame
print("\nDataFrame After Removing Columns:")
print(df)

If you want to remove multiple columns by their indices, you can use the following code:

# List of column indices to be removed
column_indices_to_remove = [1, 3]

# Get the names of the columns at the specified indices
columns_to_remove = df.columns[column_indices_to_remove]

# Drop the specified columns
df.drop(columns=columns_to_remove, inplace=True)

 

Combine two DataFrames in Pandas

Using concat to Stack DataFrames Vertically

If the two DataFrames have the same columns and you want to stack them vertically, you can use the pd.concat method:

import pandas as pd

# Define the first DataFrame
df1 = pd.DataFrame({
    'Name': ['Alice', 'Bob'],
    'Age': [25, 30],
    'City': ['New York', 'Los Angeles']
})

# Define the second DataFrame
df2 = pd.DataFrame({
    'Name': ['Charlie', 'David'],
    'Age': [35, 40],
    'City': ['Chicago', 'Houston']
})

# Concatenate the two DataFrames
result = pd.concat([df1, df2])

# Print the result
print(result)

Using merge to Join DataFrames Horizontally

If you want to join two DataFrames based on a common column (for example, an ID), you can use the pd.merge method:

# Define the first DataFrame
df1 = pd.DataFrame({
    'ID': [1, 2],
    'Name': ['Alice', 'Bob']
})

# Define the second DataFrame
df2 = pd.DataFrame({
    'ID': [1, 2],
    'Age': [25, 30]
})

# Merge the two DataFrames on the 'ID' column
result = pd.merge(df1, df2, on='ID')

# Print the result
print(result)

 

Save and load trained models in ML.NET

Throughout the model building process, a model lives in memory and is accessible throughout the application’s lifecycle. However, once the application stops running, if the model is not saved somewhere locally or remotely, it’s no longer accessible. Typically models are used at some point after training in other applications either for inference or re-training. Therefore, it’s important to store the model.

Save a model locally

When saving a model you need two things:

  1. The ITransformer of the model.
  2. The DataViewSchema of the ITransformer‘s expected input.

After training the model, use the Save method to save the trained model to a file called model.zip using the DataViewSchema of the input data.

// Save Trained Model
mlContext.Model.Save(trainedModel, data.Schema, "model.zip");

Load a model stored locally

In a separate application or process, use the Load method along with the file path to get the trained model into your application.

//Define DataViewSchema for data preparation pipeline and trained model
DataViewSchema modelSchema;

// Load trained model
ITransformer trainedModel = mlContext.Model.Load("model.zip", out modelSchema);

Checkpointing time series using Singular Spectrum Analysis (SSA) model

This code is using the CheckPoint method of the TimeSeriesPredictionEngine class in ML.NET. This method saves the state of the time series model to a file, so that it can be loaded and used for predictions later. For example, if you have a time series model that detects change points in data, you can use the CheckPoint method to save the model after training and then load it in another application to make predictions on new data.

SsaForecastingTransformer forecaster = forecastingPipeline.Fit(trainingData);

var forecastEngine = forecaster.CreateTimeSeriesEngine<ModelInput, ModelOutput>(mlContext);

// save model zip file
forecastEngine.CheckPoint(mlContext, ModelPath);