SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers!Β 

Β View Only
  • 1.  2-Step Cluster- Need to create Typing tool for new data

    Posted Fri May 09, 2025 04:45 PM

    Hi ,

    I have run 2-step cluster and got the required outputs. I have also exported model in XML. I would like to creat tryping tool using this model to classify new data. Has anyopne worked on it. Can you anyone please guide me on this. Typing tool needs to have user firndly interface since is it going to be used by non-technical people. Please help.

    Best Regards,

    Kedar



    ------------------------------
    Kedar Patgaonkar
    ------------------------------


  • 2.  RE: 2-Step Cluster- Need to create Typing tool for new data

    Posted Mon May 12, 2025 07:37 AM
    Edited by Gunilla Rudander Mon May 12, 2025 07:44 AM

    Hi Kedar, I haven't used XML-model within Excel so I asked chatGPT about it and got an answer that you should use the XML-file inside SPSS Statistics, which mean that you first has to read in the Excel data into SPSS Statistics and then run the XML-model. But I am not sure how to do that step, because in the answer below from   "How to apply the saved model" I cannot find this command. So I hope anyone else know that? /Gunilla Rudander

    Answer from chat GPT:

    You can use a TwoStep Cluster model saved in SPSS as an XML file to classify new cases, but this must be done inside SPSS - it is not possible to apply the XML file directly in Excel.

    The XML file saved by SPSS during a TwoStep Cluster analysis is an internal model format that can only be used within SPSS Statistics - there is no built-in support in Excel for interpreting or applying this type of model.

    πŸ”’ Limitations:

    • The XML file contains the model logic (cluster centers, variable types, category groupings, etc.) in a format that only SPSS understands.
    • Excel does not have an engine to interpret SPSS models or to replicate SPSS classifications.
    • TwoStep is a relatively complex algorithm that is not easily translated into Excel formulas manually.

    βœ… How to apply the saved model in SPSS

    To classify new data (e.g., from an Excel file), follow these steps inside SPSS:

    1. Load your new data
      Go to File > Open > Data and select your Excel file. Make sure the variables have the same names and formats as those used when the model was created.
    2. Apply the saved model
      • Go to Analyze > Classify > Apply Saved Model.
      • Select the file cluster_model.xml.
      • SPSS will match the variables in the model with those in the dataset.
      • Specify a new variable name for the Predicted cluster (e.g., pred_cluster).
      • Click OK.

    SPSS will add a new variable to your dataset indicating the predicted cluster for each row.

    1. Export to Excel (if needed)
      If you want to work with the results in Excel afterward, go to File > Export > Excel,



    ------------------------------
    Gunilla Rudander
    ------------------------------



  • 3.  RE: 2-Step Cluster- Need to create Typing tool for new data

    Posted Mon May 12, 2025 07:52 AM
    If you want to keep it within a spss script you can also use a python block, within it use pyreadstat & pandas.  Pandas to read the xml file, & pyreadstat to save out the .sav.  If the xml file is complicated there are other libraries.   





  • 4.  RE: 2-Step Cluster- Need to create Typing tool for new data

    Posted Mon May 12, 2025 07:53 AM

    Hi Gunilla, 

    Thanks for taking time out to explore this. Typing tool is for external clients to explore, and they may not have SPSS on the machines. Hence it makes it slightly challenging to do it in SPSS. Anyways will wait for few more answers. Thanks again. Really appreciate it.

    Best Regards,

    Kedar



    ------------------------------
    Kedar Patgaonkar
    ------------------------------



  • 5.  RE: 2-Step Cluster- Need to create Typing tool for new data

    Posted Mon May 12, 2025 09:43 AM

    Within SPSS, you can use code generated by the scoring wizard for this, but that requires SPSS.  All the information you need is in the XML file, but you would have to parse that and write the code to carry out the calculations.  The xml file or cftree files are rather complex, so this task would require significant expertise to carry out.  However, the XML file complies with the PMML standard, so apps that handle PMML could be used.  In Excel, you would need to write VBA code to process this or find a third-party add-in.



    ------------------------------
    Jon Peck
    Data Scientist
    JKP Associates
    Santa Fe
    ------------------------------



  • 6.  RE: 2-Step Cluster- Need to create Typing tool for new data

    Posted Mon May 12, 2025 10:03 AM

    You might have done this already, but if not, well, then it should not be missed: after you have saved the model in an XML-file, then you can make predictions or classifications for new data based in the model with the Scoring Wizard (found under Utilities in the menus). But is perhaps not such "simple" predictions you want to make?



    ------------------------------
    Robert Lundqvist
    Statistician
    Norrbotten County Council
    ------------------------------