<div dir="ltr">One way to handle categorical input data for machine learning is to convert it using one-hot encoding - it's not difficult but a bit cumbersome.<br>Fortunately there are other options. H2O is a machine learning library available in both Python and R that does this conversion "under the hood". <br><br>I asked ChatGPT about "machine learning with categorical inputs using H2O", she answered:<br><br>H2O is a popular open-source library for training machine learning models in Python and R. It is designed to be scalable, fast, and easy to use, and it includes a number of algorithms for classification, regression, and clustering.<br><br>H2O can handle categorical variables natively, so you don't need to use one-hot encoding or any other special techniques to work with them. When you import your data into H2O, you can specify which columns are categorical, and H2O will take care of the rest.<br><br>Here is an example of how you might use H2O to train a machine learning model with categorical inputs in Python:<br><br>Copy code<br>import h2o<br># Initialize H2O<br>h2o.init()<br># Import your data into H2O<br>df = h2o.import_file("path/to/your/data.csv")<br># Specify which columns are categorical<br>df['input_variable'] = df['input_variable'].asfactor()<br># Train a model using the categorical input_variable column<br>model = h2o.H2ORandomForestEstimator(categorical_encoding = "one_hot_explicit")<br>model.train(["input_variable"], "output_variable", df)<br>Here is an example of how you might use H2O to train a machine learning model with categorical inputs in R:<br>Copy code<br>library(h2o)<br># Initialize H2O<br>h2o.init()<br># Import your data into H2O<br>df <- h2o.importFile("path/to/your/data.csv")<br># Specify which columns are categorical<br>df[, "input_variable"] <- as.factor(df[, "input_variable"])<br># Train a model using the categorical input_variable column<br>model <- h2o.randomForest(x = "input_variable", y = "output_variable", training_frame = df)<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 7 Jan 2023 at 17:37, Eric Charles <<a href="mailto:eric.phillip.charles@gmail.com">eric.phillip.charles@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">That's somewhat helpful. Having looked up several of these algorithms (I'm still checking a few), it seems like they all input some sort of distance measure between the items (analogous to the distance between their coordinates on a cartesian graph), and then do some sort of distance-minimization function. The challenge here is that I don't have anything equivalent to that: The data is primarily categorical. <div><br></div><div>Does anyone on here actually have experience doing that kind of work?</div><div><br></div><div>It's not that it would be impossible for me to change the categorical data into something more quantitative, but doing so would bake in my assumptions about how the categories should be determined. <br><div><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div></div></div><div dir="ltr"><a href="mailto:echarles@american.edu" target="_blank"></a></div></div></div></div></div></div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jan 7, 2023 at 1:32 AM Pieter Steenekamp <<a href="mailto:pieters@randcontrols.co.za" target="_blank">pieters@randcontrols.co.za</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I asked <a href="https://chat.openai.com/chat" target="_blank">https://chat.openai.com/chat</a> and here is the conversation:<br><div><br></div><div><b>Pieter Steenekamp</b><br>can you suggest a solution for the following problem "I'm hoping someone here could help out. Let's imagine I had some data where each row was a person's career. We could list major events every year.For example: 2004 they were highered, 2007 they get a promotion, 2010 they leave for a different company, 2012 they come back at a higher level, 2015 get a promotion, then no change until 2022. Let's say I had data like this for roughly 2 million people, and that there are around 10 different types of changes that could happen during any time period (could be yearly, quarterly, monthly, I can make it how I want). I was hoping we could ask a computer to tell us if there were "types of careers" that people had. We could say "put all these careers into 4 buckets" or "7 buckets" based on similarity. Then we could look at the piles the computer made and try to make sense of them. One type might be "company man" for people who tend to stay in place for 20 or more years, another type could be a "rotator", who leaves and returns every 3 years or so. Etc. The point is, I want a computer to make the piles for me, rather than trying to come up with potential piles a priori. Are there methods for doing this? I know it's a problem we've *talked* about a lot, but I don't know if there are solutions. " <br><b><a href="https://chat.openai.com/chat" target="_blank">https://chat.openai.com/chat</a></b><br>There are several approaches that you could use to group the careers of these 2 million people into clusters based on similarity. One approach is to use unsupervised machine learning techniques, specifically clustering algorithms, to automatically group the data into clusters. Some popular clustering algorithms that you could use for this problem include k-means, hierarchical clustering, and DBSCAN (Density-Based Spatial Clustering of Applications with Noise). You could also use dimensionality reduction techniques, such as PCA (Principal Component Analysis) or t-SNE (t-Distributed Stochastic Neighbor Embedding), to reduce the dimensionality of the data and then use a clustering algorithm to group the data into clusters. Another approach is to use supervised machine learning techniques, where you would need to manually label a subset of the data with the cluster labels, and then use this labeled data to train a classifier to predict the cluster labels for the remaining data. It's worth noting that these approaches will require some feature engineering, where you will need to extract relevant features from the data that can be used to represent the careers of the people in the dataset. Once you have identified and extracted these features, you can then use them as input to the machine learning algorithms to group the data into clusters.<br><b>Pieter Steenekamp</b><br>would it then be possible to get for example if there were "types of careers" that people had?<br><b><a href="https://chat.openai.com/chat" target="_blank">https://chat.openai.com/chat</a></b><br>Yes, once you have grouped the careers of the 2 million people into clusters using one of the approaches I mentioned above, you can then analyze the characteristics of each cluster to identify common patterns and trends within each cluster. This will allow you to identify "types of careers" that people have, based on the similarity of their career events. For example, if one of the clusters is characterized by people who have had long tenures at a single company, you could label this cluster as "company man" careers. Similarly, if another cluster is characterized by people who frequently switch between companies, you could label this cluster as "rotator" careers. You can then use this information to gain insights into the types of careers that are represented in the dataset, and potentially draw conclusions about the factors that may influence career paths and success.<br><b>Pieter Steenekamp</b><br>can you propose python code to do sometingh like this please<br><b><a href="https://chat.openai.com/chat" target="_blank">https://chat.openai.com/chat</a></b><br>Sure, here is an example of how you could use the scikit-learn library in Python to group the careers of the 2 million people into clusters using the k-means algorithm:<br>Copy code<br>from sklearn.cluster import KMeans<br># Load the data into a NumPy array<br>data = np.loadtxt('career_data.txt')<br># Create the k-means model<br>model = KMeans(n_clusters=4)<br># Fit the model to the data<br>model.fit(data)<br># Predict the cluster labels for each data point<br>labels = model.predict(data)<br># Print the cluster labels<br>print(labels)<br>This code will group the data into 4 clusters, as specified by the n_clusters parameter. You can adjust this parameter to change the number of clusters that the data is grouped into.<br>To extract features from the data that can be used as input to the k-means model, you will need to preprocess the data and select relevant features. This will likely involve some feature engineering, which will depend on the specific characteristics of the data and the goals of your analysis.<br><div>I hope this helps! Let me know if you have any questions. </div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 6 Jan 2023 at 19:34, Eric Charles <<a href="mailto:eric.phillip.charles@gmail.com" target="_blank">eric.phillip.charles@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Greetings all,<div>I'm hoping someone here could help out. Let's imagine I had some data where each row was a person's career. We could list major events every year. <br><br>For example: 2004 they were highered, 2007 they get a promotion, 2010 they leave for a different company, 2012 they come back at a higher level, 2015 get a promotion, then no change until 2022. </div><div><br></div><div>Let's say I had data like this for roughly 2 million people, and that there are around 10 different types of changes that could happen during any time period (could be yearly, quarterly, monthly, I can make it how I want). </div><div><br></div><div>I was hoping we could ask a computer to tell us if there were "types of careers" that people had. We could say "put all these careers into 4 buckets" or "7 buckets" based on similarity. Then we could look at the piles the computer made and try to make sense of them. </div><div><br></div><div>One type might be "company man" for people who tend to stay in place for 20 or more years, another type could be a "rotator", who leaves and returns every 3 years or so. Etc. The point is, I want a computer to make the piles for me, rather than trying to come up with potential piles a priori.</div><div><br></div><div>Are there methods for doing this? I know it's a problem we've *talked* about a lot, but I don't know if there are solutions. <br><br>Any help would be appreciated.</div><div><br clear="all"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><span style="color:rgb(34,34,34)">Best,<br>Eric<br><br></span><div></div></div><div dir="ltr"><a href="mailto:echarles@american.edu" target="_blank"></a></div></div></div></div></div></div></div></div>
-. --- - / ...- .- .-.. .. -.. / -- --- .-. ... . / -.-. --- -.. .<br>
FRIAM Applied Complexity Group listserv<br>
Fridays 9a-12p Friday St. Johns Cafe / Thursdays 9a-12p Zoom <a href="https://bit.ly/virtualfriam" rel="noreferrer" target="_blank">https://bit.ly/virtualfriam</a><br>
to (un)subscribe <a href="http://redfish.com/mailman/listinfo/friam_redfish.com" rel="noreferrer" target="_blank">http://redfish.com/mailman/listinfo/friam_redfish.com</a><br>
FRIAM-COMIC <a href="http://friam-comic.blogspot.com/" rel="noreferrer" target="_blank">http://friam-comic.blogspot.com/</a><br>
archives: 5/2017 thru present <a href="https://redfish.com/pipermail/friam_redfish.com/" rel="noreferrer" target="_blank">https://redfish.com/pipermail/friam_redfish.com/</a><br>
1/2003 thru 6/2021 <a href="http://friam.383.s1.nabble.com/" rel="noreferrer" target="_blank">http://friam.383.s1.nabble.com/</a><br>
</blockquote></div>
-. --- - / ...- .- .-.. .. -.. / -- --- .-. ... . / -.-. --- -.. .<br>
FRIAM Applied Complexity Group listserv<br>
Fridays 9a-12p Friday St. Johns Cafe / Thursdays 9a-12p Zoom <a href="https://bit.ly/virtualfriam" rel="noreferrer" target="_blank">https://bit.ly/virtualfriam</a><br>
to (un)subscribe <a href="http://redfish.com/mailman/listinfo/friam_redfish.com" rel="noreferrer" target="_blank">http://redfish.com/mailman/listinfo/friam_redfish.com</a><br>
FRIAM-COMIC <a href="http://friam-comic.blogspot.com/" rel="noreferrer" target="_blank">http://friam-comic.blogspot.com/</a><br>
archives: 5/2017 thru present <a href="https://redfish.com/pipermail/friam_redfish.com/" rel="noreferrer" target="_blank">https://redfish.com/pipermail/friam_redfish.com/</a><br>
1/2003 thru 6/2021 <a href="http://friam.383.s1.nabble.com/" rel="noreferrer" target="_blank">http://friam.383.s1.nabble.com/</a><br>
</blockquote></div>
-. --- - / ...- .- .-.. .. -.. / -- --- .-. ... . / -.-. --- -.. .<br>
FRIAM Applied Complexity Group listserv<br>
Fridays 9a-12p Friday St. Johns Cafe / Thursdays 9a-12p Zoom <a href="https://bit.ly/virtualfriam" rel="noreferrer" target="_blank">https://bit.ly/virtualfriam</a><br>
to (un)subscribe <a href="http://redfish.com/mailman/listinfo/friam_redfish.com" rel="noreferrer" target="_blank">http://redfish.com/mailman/listinfo/friam_redfish.com</a><br>
FRIAM-COMIC <a href="http://friam-comic.blogspot.com/" rel="noreferrer" target="_blank">http://friam-comic.blogspot.com/</a><br>
archives: 5/2017 thru present <a href="https://redfish.com/pipermail/friam_redfish.com/" rel="noreferrer" target="_blank">https://redfish.com/pipermail/friam_redfish.com/</a><br>
1/2003 thru 6/2021 <a href="http://friam.383.s1.nabble.com/" rel="noreferrer" target="_blank">http://friam.383.s1.nabble.com/</a><br>
</blockquote></div>